Question

I may have the terminology wrong in my question, but here's my best attempt:

the ARC for my ios app has the autoreleasepool enabled. Therefore I don't release memory at my choosing, but it seems like it's on a GC pickup rather.

I'm having trouble getting dealloc to run for a particular UIView that has been removed from it's super view. Is this normal?

Was it helpful?

Solution

All ARC does is make sure that retain and release messages are sent at the appropriate times (when you start and stop referring to an object). There is no GC -- the deallocs are exactly as before -- which is they are done when the retain count gets to 0.

The autorelease pool is for when you call autorelease instead of release. This means to delay the release call by putting it into a queue managed by an autorelease pool -- when the pool is drained, every object in the queue has release called on it.

So, if you are depending on ARC --

  1. don't call retain, release or autorelease yourself -- you get a build error if you try anyway

  2. use (strong) properties to hold onto references that you need to stay around

  3. if you end up with a circular reference -- a strong pointer pointing to an object that strong points back -- then this all falls apart -- ARC won't release anything. You either need to set one of the pointers to nil, or make one of them weak.

Put break-points where you think the dealloc should be called and check the objects retainCount. Use the Leaks instrument to figure out what might be going on.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top