• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Memory management puzzle
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Memory management puzzle


  • Subject: Memory management puzzle
  • From: DKJ <email@hidden>
  • Date: Wed, 26 Nov 2008 18:49:57 -0800

I've got something this in my code, which is run several times by the app:

	UIView *subView = [[MyView alloc] initWithFrame:frame];
	[theView addSubview:subView];
	[subView release];

Later on this happens:

	[subView removeFromSuperView];
	subView = nil;

These two code snippets are in different controller methods. I'm certain they're called the same number of times.

The docs say that subView gets a release message when removeFromSuperview is called. But the NSLog statement I put in the dealloc method for MyView is never called. The ObjectAlloc instrument shows the count of MyView instances increasing by 1 each time the code is run. And the Leaks instrument shows no leaks at all.

Just to see what would happen, I put [subView release] after the call to removeFromSuperview. My NSLog statement was then called twice; and of course I got an EXC_BAD_ACCESS as well.

I really want to get rid of these subView objects. Why aren't they being deallocated? And since they're not, why am I not getting any leaks when I set subView = nil?

dkj
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Memory management puzzle
      • From: Jens Miltner <email@hidden>
    • Re: Memory management puzzle
      • From: Andy Lee <email@hidden>
    • Re: Memory management puzzle
      • From: Roland King <email@hidden>
  • Prev by Date: Re: Sort Through Commas in Cocoa
  • Next by Date: Re: Scheme for efficiently archiving images.
  • Previous by thread: Re: Sort Through Commas in Cocoa
  • Next by thread: Re: Memory management puzzle
  • Index(es):
    • Date
    • Thread