Re: [newbie] NSString code so it won't leak
Re: [newbie] NSString code so it won't leak
- Subject: Re: [newbie] NSString code so it won't leak
- From: Dean Davis <email@hidden>
- Date: Wed, 11 Sep 2002 12:42:06 -0700 (PDT)
I'll look at the app when I get home tonight and see
if I posted the wrong version.
To test all you need to do is press the button once.
This starts the timer which will fire every 30 seconds
and run the code to download the HTML and send it to
the offending method for leaking.
I added the "Stop" button so one could stop the timer
so one could "pause" ObjectAlloc to examine the
objects.
If you "Pause" ObjectAlloc while a timer is running in
the program being tested the whole things crashes when
the timer fires. (at least this is what I found in
this example).
Anyhow, when I run the program under ObjectAlloc what
I saw was that everytime NSTimer would fire objects of
type NSString (or CFString, I forget) would just stack
up.
Also, if I don't free "sender" in
URLHandleResourceDidFinishLoading objects of type
CFHTPPURLHandle (or something like that) and a bunch
of what looked to be NSURL releated objects would
start to stack up (one object for each time the timer
would fire).
As for the other code leaking, my app was not intended
to be professional just illustrative.
Overall, in order to test the way I was, I would do
this.
Start ObjectAlloc and point it to the binary inside
the bundle of LeakTest.
Let ObjectAlloc run until all the numbers stabilize
(about 30-40 seconds).
Open the Standard Output window so you can see the
NSLog entries.
Switch to LeakTest and click the button "Button" ONCE.
30 seconds later the timer will fire and download
yahoo.com, let the numbers stabiliaze again (2-3
seconds). Choose "Mark" from ObjectAlloc and wait for
the timer to fire again.
Let it fire three or four more times.
Switch to LeakTest and click "Stop" button.
The program will "crash" inside of ObjectAlloc but all
the objects and numbers will still be there to
examine.
If you have released "sender" then the only objects
remaining should be CFStrings and CFArrays (from my
memory). If you take out the [sender release] code
then many other objects will be hanging out.
Dean Davis
--- James DiPalma <email@hidden> wrote:
>
> I have an example program that leaks. Has anyone
>
even
>
> botherd to look at it?
>
>
I looked at your code and I have a few comments
>
>
- pushButton: will leak a MyFee object every time
>
pressed *
>
- URLHandleResourceDidFinishLoading: should not
>
release filedata
>
- URLHandleResourceDidFinishLoading: should not
>
release sender
>
- When MinuteTimer fires a second time, your app
>
crashes
>
- leaks (a command line tool) reports 0 leaks (app
>
doesn't crash
>
after fixing extra releases)
>
>
I used ObjectAlloc to see what residual NSStrings
>
your code leaves
>
around after your 1st firing:
>
>
I see 3 or 4 CFString (CFSTR)
>
"DiskArbMode" from
>
InitializeDiskArbitrationMessages
>
"/usr/share/zoneinfo/" from NSLog
>
";?/" from NSLog
>
"d-d-d d:d:.3f %s[%d] %s " from
>
NSLog
>
>
I see 4 CFString (immutable)
>
"US/Eastern" from NSLog
>
"EDT" from NSLog
>
"EST" from NSLog
>
"EWT" from NSLog
>
>
All of these strings seem to go away if you wait a
>
little bit (maybe
>
NSLog caches strings for this "2002-09-11
>
14:00:46.249 LeakTest[5309]").
>
Not one of these strings is from your code.
>
>
>
-jim
>
>
>
* you have no dealloc method which could release one
>
instance, but
>
multiple button presses would still leak. Not a big
>
deal since this code
>
is clearly designed as a test, but simple init and
>
dealloc methods are
>
good practice.
>
_______________________________________________
>
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.
__________________________________________________
Yahoo! - We Remember
9-11: A tribute to the more than 3,000 lives lost
http://dir.remember.yahoo.com/tribute
_______________________________________________
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.