Add a comment. Active Oldest Votes. Since almost every class in the Cocoa framework is subclassed at least from NSObject , this line is necessary for proper memory release. Improve this answer. Alexander Alexander 8, 1 1 gold badge 32 32 silver badges 44 44 bronze badges. The Overflow Blog. Does ES6 make JavaScript frameworks obsolete? Podcast Do polyglots have an edge when it comes to mastering programming Sign up or log in Sign up using Google.
Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Does ES6 make JavaScript frameworks obsolete? Podcast Do polyglots have an edge when it comes to mastering programming Featured on Meta. Now live: A fully responsive profile.
Linked Related Hot Network Questions. Question feed. Stack Overflow works best with JavaScript enabled. The runtime will do that for you when the object is no longer needed which the runtime decides as well. Just make sure you retain and release properly. Do not call dealloc on other objects. Asked By: Sujal. Answered By: Caleb. I am not quite that gullible anymore. Object lifetime and clean-up should not be a riddle.
What leads people to believe this is a bug or oversight? There is nothing else to call it. How do you suggest that these resources get released or shutdown properly?
Jerking the rung out from under an object is a bad plan.. It can lead to many stability and reliablity issues. There are many resources in a system, not just memory….
Objects MUST have defined lifetimes and be closed properly and reliably for software to work in the real world. A whole lot of Java, Lisp, SmallTalk, and Python programmers were no doubt shocked to realize that none of the software they have ever written works in the real world. Relying on dealloc to free external resources is a bad idea. This is hardly unique to Cocoa. Java and other garbage-collected languages heavily discourage it since garbage collection is nondeterministic, and so there is no guarantee your external resource will ever get freed.
Cocoa with autorelease pools are in a similar situation, so relying on dealloc to release your external resources is a poor idea. Programming is inherently difficult. Complaining about this one little difference that takes five seconds to understand and which occurs in many other programming environments is just ridiculous. Class destruction is not a preconception… It is a reality, a rule, and a generally expected behaviour.
My point is this.. If I create an instance of a class, it is my responsiblity to destroy that instance.. I find that a little bit shocking! If I let my programming staff code that way, I would hate to think of the support calls we would have! I agree programming is difficult, but a few rules, consistently applied, sure make life easier.
The framework create the instance of this class, so IT is responsible to destroy it properly.. Do you really think that is a preconception? Therefore, I submit that this is the bug Apple should fix.. I would prevent everyone from jumping through hoops to try to accomplish a work-around, and hours of wasted time trying to justify a mistake. For sure, I will move on.. Nothing is being leaked in the standard case. The only time you will leak resources is if you incorrectly rely on dealloc to release external resources.
Your strawman attack annoys me greatly. Garbage collection is not a different issue. GC makes no guarantees that any one object will ever be destroyed.
So you would still leak in that case. Better to clean up properly. The standard technique is to simply have a -close call that you invoke manually. If this disturbs you too much, have your objects listen for NSApplicationWillTerminate notifications.
Your problem is in insisting that this is an obvious bug. You should consider the possibility that there is more than one correct way to do things. This is a non-issue. The OS will free the memory your app is using when it tears down your process, much faster than it could by walking the object trees and call dealloc.
0コメント