Re: Thread memory leak
Re: Thread memory leak
- Subject: Re: Thread memory leak
- From: "John C. Randolph" <email@hidden>
- Date: Fri, 6 Jun 2003 12:54:12 -0700
On Friday, June 6, 2003, at 09:43 AM, Chuck Rice wrote:
I have a thread defined that runs async to the rest or my program to
keep a USB attached LDC display updated with current status
information. Works great, except for this huge memory leak! :( The
memory leak goes away if I comment out this line in the code:
[NSThread sleepUntilDate:[NSDate
dateWithTimeIntervalSinceNow:0.001]];
With this line active I get a 10 to 20 Meg memory leak every minute. I
am still an obj-C newbie, so forgive me if it is obvious. -Chuck-
Well, in the line of code above, you're creating a new NSDate, which
will hang around until the autorelease pool gets released. If you're
generating a thousand of these a second (as the code above would seem
to indicate), the memory used would grow as you describe.
So, let me be the first to ask you the question that all new Cocoa
programmers get asked: "What, exactly, are you trying to do?" ;-)
I suspect that you actually want something to happen every milisecond,
in which case you should look into using the NSTimer class.
-jcr
John C. Randolph <email@hidden> (408) 974-8819
Sr. Cocoa Software Engineer,
Apple Worldwide Developer Relations
http://developer.apple.com/cocoa/index.html
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.