Don't dealloc

I have this in supervision:

mySubView = [[MySubView alloc] init];
[self addSubview:mySubView];
[mySubView release];

      

then at some point later, in the sub-clause, this:

[self removeFromSuperview];

      

when i debug it i notice that the dealloc for the subview is never called, although i'm pretty sure the refcount should be 0. any ideas why that might be? thank.

+2


source to share


4 answers


Yes, when you submit removeFromSuperview then post the posted message afterwards. And each call to release reduces the number of retentions. And in case:

MySubView * mySubView = [[MySubView alloc] init];
[window addSubview:mySubView];
[mySubView release];
[mySubView removeFromSuperview];

      



the result will be as you expect: after removing FromSuperview mySubView, count count will become 0 and dealloc will be called.

but there is more code in your example, followed by "later at some point later" and another object (and it is not a supervisor) stores mySubView. You can, for example, provide a log keepCount value to see where your view is saved / deleted.

+3


source


You cannot rely on keepCount to provide any useful debugging information. This may help you in some cases, but Apple says:



Important: This method is generally irrelevant when debugging memory management problems. Since any number of infrastructure objects can store an object to store references to it, while autocomplete pools can contain any number of pending releases on an object, it is very unlikely that you can get useful information from this method. To understand the basic rules of memory management that you must follow, read "Memory Management Rules". To diagnose memory management problems, use the right tool: The LLVM / Clang Static analyzer can usually find memory management problems even before your program runs. Object Alloc tool in Tools application (see Tools User Guide) can track the distribution of objects and their destruction. Shark (see the Shark User's Guide) also describes memory allocation (among many other aspects of your program).

+1


source


I don't know if removeFromSuperview does this , but the pointer in supervision should be released. If removeFromSuperview only frees the pointer in the subview for the supervisor, and not the pointer in the supervisor for the subview, that might be the source of your problem.

0


source


I'm pretty sure the reference count should be 0.

You? Why?

Forget to keep the count. Just think about object ownership, because accounts are almost completely pointless as an aid to debug memory management.

Apple provides many tools for debugging memory management problems. Use them.

This link might be helpful.

http://developer.apple.com/iphone/library/documentation/Performance/Conceptual/ManagingMemory/Articles/FindingPatterns.html

0


source







All Articles