• 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
Re: Memory management puzzle
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Memory management puzzle


  • Subject: Re: Memory management puzzle
  • From: Roland King <email@hidden>
  • Date: Thu, 27 Nov 2008 12:18:53 +0800

hmm - I do believe this works for me, I have views being destroyed in my app and they are going away.

Have you tried something a bit gross and disgusting which is getting the current refcount before and after the removeFromSuperView? I know that you cannot use the absolute value of your refcount to determine when something is going to be released, however you may be able to satisfy yourself that removeFomSuperView: is doing what it says and then go looking elsewhere.

DKJ wrote:

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


_______________________________________________

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: Scott Ribe <email@hidden>
References: 
 >Memory management puzzle (From: DKJ <email@hidden>)

  • Prev by Date: Re: to get handle to "File/1.jpg"
  • Next by Date: Re: Scheme for efficiently archiving images.
  • Previous by thread: Memory management puzzle
  • Next by thread: Re: Memory management puzzle
  • Index(es):
    • Date
    • Thread