• 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: ObjectAlloc and objects that should have been released
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ObjectAlloc and objects that should have been released


  • Subject: Re: ObjectAlloc and objects that should have been released
  • From: Miles <email@hidden>
  • Date: Sun, 26 Apr 2009 12:16:44 -0700

I've narrowed this down to the smallest case I can.

I have a method that loads a view and immediately releases it:

    UIWindow *win                    = [UIApplication
sharedApplication].keyWindow;
    TestVC *test = [[TestVC alloc] init];
    [win addSubview:test.view];
    [test.view removeFromSuperview];
    [test release];

And here is the entire TestVC class:

#import "TestVC.h"

@implementation TestVC

- (id)init
{
    self = [super init];
    if (self){}
    return self;
}

// Implement loadView to create a view hierarchy programmatically, without
using a nib.
- (void)loadView {

    UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen
mainScreen] applicationFrame]];
    contentView.backgroundColor = [UIColor blackColor];
    contentView.autoresizesSubviews = YES;
    [contentView release];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)dealloc {
    [super dealloc];
}

@end


When I look in ObjectAlloc, TestVC points to the "UIView *contentView"
declaration as created and still living. Is this just an objectAlloc bug, or
is there some other sort of autorelease thing that goes on behind the
scenes? I don't see any reason why this would still be hanging around.

Ugh.







On Fri, Apr 24, 2009 at 7:18 PM, Miles <email@hidden> wrote:

> Very interesting, I'll give all that a shot and report back. Thanks so
> much!
>
>
>
>
> On Apr 24, 2009, at 7:07 PM, Peter N Lewis <email@hidden> wrote:
>
>  On 25/04/2009, at 8:28 , Miles wrote:
>>
>>> I just mean that I'm adding some labels and images to the view. I have
>>> quadruple checked that they are all being released, but I must be
>>> overlooking something.
>>>
>>
>> I doubt its your issue, but I recently had a problem like this that took
>> me far too long to track down.
>>
>> The debugging technique I used was to override retain/release/autorelease
>> and dealloc and have them just call NSLog and super, then set a breakpoint
>> on each, add a backtrace "bt" debugging command and set them to
>> auto-continue.
>>
>> Eventually, after much hair pulling I tracked it down to my
>> removeFromSuperview override neglecting to call super - ouch!
>>
>> But one technique for finding this might be to make a trivial subclass of
>> UIImage that does the above and use it for logo.
>>
>> One other possibility would be - does UIImage cache images created with
>> initWithContentsOfFile?  The tehcnique above might tell you if thats what is
>> happening, because you should see UIImage system code adding it to an
>> array/dictiuonary/set and not releasing it later.
>>
>> Enjoy,
>>  Peter.
>>
>> --
>>    Run macros from your iPhone with Keyboard Maestro Control!
>>        or take a break with Derzle for your iPhone
>>
>> Keyboard Maestro <http://www.keyboardmaestro.com/> Macros for your Mac
>> Aragom Space War <http://www.stairways.com/iphone/aragom> Don't get
>> killed!
>> Derzle <http://www.stairways.com/iphone/derzle> Enjoy a relaxing puzzle.
>> <http://www.stairways.com/>           <http://download.stairways.com/>
>>
>>
>>
>>
>> _______________________________________________
>>
>> 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: ObjectAlloc and objects that should have been released
      • From: Miles <email@hidden>
References: 
 >ObjectAlloc and objects that should have been released (From: Miles <email@hidden>)
 >Re: ObjectAlloc and objects that should have been released (From: Peter N Lewis <email@hidden>)
 >Re: ObjectAlloc and objects that should have been released (From: Miles <email@hidden>)
 >Re: ObjectAlloc and objects that should have been released (From: Alexander Spohr <email@hidden>)
 >Re: ObjectAlloc and objects that should have been released (From: Miles <email@hidden>)
 >Re: ObjectAlloc and objects that should have been released (From: Peter N Lewis <email@hidden>)
 >Re: ObjectAlloc and objects that should have been released (From: Miles <email@hidden>)

  • Prev by Date: Re: NSTask, or threading?
  • Next by Date: Re: NSTask, or threading?
  • Previous by thread: Re: ObjectAlloc and objects that should have been released
  • Next by thread: Re: ObjectAlloc and objects that should have been released
  • Index(es):
    • Date
    • Thread