• 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: Since when does caling [NSTimer invalidate] release the object that spawned it?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Since when does caling [NSTimer invalidate] release the object that spawned it?


  • Subject: Re: Since when does caling [NSTimer invalidate] release the object that spawned it?
  • From: Fritz Anderson <email@hidden>
  • Date: Thu, 18 Aug 2005 11:25:18 -0500


On 16 Aug 2005, at 9:31 PM, Timothy J. Wood wrote:

On Aug 16, 2005, at 6:59 PM, Walt Horat wrote:

Subject says all. Code is:

- (IBAction) someMethod
{
    m_closeAlpha = 1.0;
    m_closeTimer = [NSTimer scheduledTimerWithTimeInterval:0.1
        target:self
        selector:@selector(windowCloseFade:)
        userInfo:self
        repeats:TRUE];


Zombie here...

}

- (IBAction) windowCloseFade: (id) sender
{
if (m_closeAlpha <= 0.0)
{
if (nil != m_closeTimer)
{
[m_closeTimer invalidate]; // invalidate our current timer
m_closeTimer = nil;
}
}
else
{
m_closeAlpha -= 0.0125; //(8 second fade)
[[self window] setAlphaValue: m_closeAlpha];
}
}

... probably causes crash here.

We crash on the call to invalidate. Looking up the stack, I can see it trying to deallocate the object that instantiated it (i.e. "self" in the call to create the timer). NOTE: frame #4 is the [m_closeTimer invalidate] statement. Why would invalidating my timer invalidate me?
...
Why, oh why... Why would it do that?
The NSTimer method returns an autoreleased instance :)

Yes, but a timer that is retained by the current run loop until the timer is invalidated. You'll notice that the crash occurred on an attempt to release the _target_, not the timer.


NSTimer retains its target. When invalidated, it releases the target. That's a balanced release. Look elsewhere for an extra release of the target object.

    -- F

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >[NEWBIE] windowDidBecomeKey ? (From: Stephane Pinel <email@hidden>)
 >Since when does caling [NSTimer invalidate] release the object that spawned it? (From: Walt Horat <email@hidden>)
 >Re: Since when does caling [NSTimer invalidate] release the object that spawned it? (From: "Timothy J. Wood" <email@hidden>)

  • Prev by Date: SOLVED : Transparent NSTableView. Is it possible?
  • Next by Date: Re: Transparent NSTableView. Is it possible?
  • Previous by thread: Re: Since when does caling [NSTimer invalidate] release the object that spawned it?
  • Next by thread: [ANN] Typed Stream Viewer
  • Index(es):
    • Date
    • Thread