• 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: static analyzers says I'm leaking, I _think_ I'm not
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: static analyzers says I'm leaking, I _think_ I'm not


  • Subject: Re: static analyzers says I'm leaking, I _think_ I'm not
  • From: Daniel Höpfl <email@hidden>
  • Date: Thu, 07 May 2015 13:44:48 +0200

Hi,

Expanding the "potential leak" message yields:

Static analyser is right, there is a potential leak.

Based on what Aaron said, assume the following usage of your class:

LifeGrid *grid = [[LifeGrid alloc] init];
// GridCycler is allocated (retain count: +1)
// GridCycler is retained by property assignment (retain count: +2)

grid.cycler = nil;
// GridCycler property retainment is released (retain count: +1)
// No new object to retain.

[grid release];
// property is nil, your release call is ignored -> leak.


Even worse, resulting in crash (double dealloc) on/after autorelease drain:

LifeGrid *grid = [[LifeGrid alloc] init]; // A: +2
grid.cycler = [[[GridCycler alloc] initWithGrid:grid] autorelease]; // A: +1, B: +2, AR pending. [grid release]; // cyclerA: +1, cyclerB: 0, but still 1 autorelease pending (!)


I'd change the code as follows:

// init
self.cycler = [[[GridCycler alloc] initWithGrid: self] autorelease];

// alternative init, if you want to bypass the autorelease pool:

GridCycler *cycler = [[GridCycler alloc] initWithGrid: self];
self.cycler = cycler;
[cycler release];
// Don't use [self.cycler release], one day you might change the property to copy.


// dealloc:
// nothing.

Bye,
   Daniel

_______________________________________________

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: static analyzers says I'm leaking, I _think_ I'm not
      • From: Charles Srstka <email@hidden>
References: 
 >static analyzers says I'm leaking, I _think_ I'm not (From: Michael David Crawford <email@hidden>)

  • Prev by Date: Re: Help: NSScrollView is resizing its documentView down to (0, 0)
  • Next by Date: Does the NSView Drag Protocol has any issues with non-key windows?
  • Previous by thread: Re: static analyzers says I'm leaking, I _think_ I'm not
  • Next by thread: Re: static analyzers says I'm leaking, I _think_ I'm not
  • Index(es):
    • Date
    • Thread