Re: NSTimer Question (Crash when it fires)
Re: NSTimer Question (Crash when it fires)
- Subject: Re: NSTimer Question (Crash when it fires)
- From: Bert Torfs <email@hidden>
- Date: Fri, 3 Dec 2004 10:10:08 +0100
Brian,
You were right actually!. NSTimers retain the object they are created
with (the target paramater). As the timer was released in the dealloc
method of its target, the timer never got released (the dealloc was
never called as the timer held it - chicken and egg). So it kept on
running,even when the window was closed.
I moved the timer to the NSDocument subclass where it belongs and I
release it in the close method. Works fine now.
BTW : the retain when creating the times was wrong too!. Timers get
retained by the runloop. The retain created a memory leak.
Bert
On Dec 2, 2004, at 23:10, Brian Bergstrand wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
IB outlets are only valid while the window is open. When the window is
closed and the resources destroyed you are left with dangling pointers
which will crash if you access them. Is your timer firing while you
window is closed?
On Dec 2, 2004, at 2:59 PM, Bert Torfs wrote:
Dear all,
following method runs OK if I call it directly from my code. When I
call it via an NSTimer however, my program crashes when getting the
arrangedObjects from the 'theStockArrayController'.
//=======Snippet start
-(void)calculateStockPrices:(NSTimer*)theTimer
{
NSArray* theCurrencyArray;
//theStockArrayController is an IBOutlet connected via Interface
builder
//to a standard arrayController. We need to loop over the array it
controls
if (theStockArrayController)
{
//This crashes if called from a timer
theCurrencyArray = [theStockArrayController arrangedObjects];
//The rest is of no importance
}
}
//=======Snippet end
The timer is created with the following statement :
theRefreshTimer = [[NSTimer
scheduledTimerWithTimeInterval:(NSTimeInterval)theRefreshRate*60
target:self
selector:@selector(calculateStockPrices:)
userInfo:NULL
repeats:YES]retain];
any idea?
Thanks a lot,
Brian Bergstrand <http://www.bergstrand.org/brian/>, AIM: triryche206
PGP Key: <http://www.bergstrand.org/brian/misc/public_key.txt>
A banker is a fellow who lends you his umbrella when the sun is
shining, but wants it back the minute it begins to rain. - Mark Twain
As of 04:04:25 PM, iTunes is playing "Slaying The Dreamer" from
"Century Child" by "Nightwish"
-----BEGIN PGP SIGNATURE-----
Version: PGP 8.1
iQA/AwUBQa+EsXnR2Fu2x7aiEQLjOQCfQPBHTacuRYWnvWwEWfZk6HxP5wAAnje+
nc1Lj+mpzRsziwB0cNrk3JzX
=9Mez
-----END PGP SIGNATURE-----
_______________________________________________
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