user945620
user945620

Reputation:

Does autorelease hide leaks in Instruments?

Here is a scenario that appears to trick Leaks:

  1. Generate UIView *v from a Nib or using alloc/init.
  2. Allocate, init, and autorelease a bunch more views e.g. UIButton, and attach them to the UIView as subviews.
  3. Release the view v.

That's it. The subviews are not released, but Leaks will not see them either.

Has anyone else seen this?

Note: The solution to this problem is to removeFromSuperview anything attached to v.

Thanks.

Upvotes: 0

Views: 78

Answers (2)

hwaxxer
hwaxxer

Reputation: 3383

You need to read up on the memory guidelines.

You have done your part of the memory management by autoreleasing the UIViews you created, and you have transferred the ownership of them to UIView v.

Edit

After reading your comments it seems like they are actually not getting released, which could be to a circular reference. Are you sure nothing else is retaining the view? How are you instantiating them?

Upvotes: 1

Nick Lockwood
Nick Lockwood

Reputation: 41005

What makes you think that they aren't released?

It sounds like your retains and releases are balanced, so they should be released correctly. What may be confusing you is that because they are autoreleased, they won't be released right away but will instead be released 1/60th second later when the autorelease pool is flushed.

In case it helps clarify things: Views automatically retain subviews when they are added, and release them when they are themselves released (just like adding items to an array).

Upvotes: 1

Related Questions