Re: ObjectAlloc and objects that should have been released
Re: ObjectAlloc and objects that should have been released
- Subject: Re: ObjectAlloc and objects that should have been released
- From: Miles <email@hidden>
- Date: Fri, 1 May 2009 08:32:08 -0700
Hi guys-
I'm still really struggling with this. I keep creating the most simple
examples I can and ObjectAlloc continues to show objects as 'created and
still living' when they really shouldn't be. At this point I would probably
just assume it's a bug in ObjectAlloc or elsewhere but over time my app is
using more memory so I do have issues to track down. This issues I'm seeing
make it really hard to narrow them down.
For example, I have created a new project where the delegate creates and
immediately releases a view controller that doesn't have anything in it at
all. Object alloc still shows a handful of objects as created and still
living, such as:
# Object Address Category Creation Time Size Responsible
Library Responsible Caller
1877 0x527c30 GeneralBlock-32 00:01.444 32 ObjectAllocTest
-[ObjectAllocTestAppDelegate applicationDidFinishLaunching:]
1878 0x527540 GeneralBlock-128 00:01.444 128
ObjectAllocTest -[ObjectAllocTestAppDelegate
applicationDidFinishLaunching:]
1879 0x5085f0 GeneralBlock-128 00:01.409 128
ObjectAllocTest start
1880 0x50ca20 GeneralBlock-48 00:01.446 48 ObjectAllocTest
-[MainViewController dealloc]
1881 0x5295c0 GeneralBlock-32 00:01.444 32 ObjectAllocTest
-[ObjectAllocTestAppDelegate applicationDidFinishLaunching:]
1882 0x50ab10 GeneralBlock-48 00:01.446 48 ObjectAllocTest
-[MainViewController dealloc]
1883 0x529970 GeneralBlock-32 00:01.444 32 ObjectAllocTest
-[ObjectAllocTestAppDelegate applicationDidFinishLaunching:]
1884 0x1013000 GeneralBlock-1536 00:01.444 1536
ObjectAllocTest -[ObjectAllocTestAppDelegate
applicationDidFinishLaunching:]
All of the ones that say "[ObjectAllocTestAppDelegate
applicationDidFinishLaunching:]" point to the line where I create mainMVC.
The ones that say to "[MainViewController dealloc]" point to "[super
dealloc]" (which seems very odd)
*Here's the entire appDelegate:*
#import "ObjectAllocTestAppDelegate.h"
#import "MainViewController.h"
@implementation ObjectAllocTestAppDelegate
@synthesize window;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
mainVC = [[MainViewController alloc] init];
[mainVC release];
mainVC = nil;
[window makeKeyAndVisible];
}
- (void)dealloc {
NSLog(@"dealloc delegate");
[mainVC release];
[window release];
[super dealloc];
}
@end
*And here's the entire view controller:*
#import "MainViewController.h"
@implementation MainViewController
-(void)loadView {
}
- (id)init {
if (self = [super init]) {}
return self;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)dealloc {
NSLog(@"dealloc mvc");
[super dealloc];
}
@end
On Sun, Apr 26, 2009 at 12:55 PM, Miles <email@hidden> wrote:
>
> Wow. In that particular example it was '[UIScreen mainScreen]
> applicationFrame' that was causing the problem. When I changed that to a
> CGRectMake, the view was not longer living once I released it. Does
> '[UIScreen mainScreen] applicationFrame' cause some sort of caching issue?
>
> Now I'm at a point where this is keeping the view around longer than I
> think it should:
>
> NSDictionary *rootDict = [[NSDictionary alloc] initWithContentsOfFile:
> filePath];
> [rootDict release];
>
> Could someone please explain what this is all about?
>
> Thanks!
>
>
>
>
> On Sun, Apr 26, 2009 at 12:16 PM, Miles <email@hidden> wrote:
>
>> 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