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: Thu, 12 Sep 2002 12:07:55 -0700 (PDT)
--- James DiPalma <email@hidden> wrote:
>
> Funny, after Jim's "Buddy, your code isn't leaking
>
> everyone in the world had told you this and you
>
choose
>
> to ignore this so your a bone-head"
>
>
That is a mis characterization of my post. You
>
continue to show a
>
disregard for my help.
>
What help? You NEVER saw the problem so how could you
help?
Shawn Erickson helped.
So once again, I never really thought NSString was
leaking but ObjectAlloc was telling me something
different and I was following all the memory
management rules in terms of my NSString objects so I
asked the list for help becuase I was obviously
missing something and thanks to Shawn finally got some
help beyond the basics which I had already covered
before my original post.
Now, my original post wasn't a very good example
because my example code in that posting wouldn't leak
because I filtered out using a timer and an
NSURLHandle and a callback to a different object.
Which it turns out is part of the essence of the
problem.
But, that is why I posted the program that showed
objects stacking up.
It was irrelevant that the code would crash due to
[filedata release] and [sender release]. Take those
lines out and the NSStrings would still stack up which
was the point of my original question.
Here's one more thing. Take my original app with the
bad [sender release] and [filedata release]. Have
Console running, start "LeakTest", click the button to
start the timer. You now have 30 seconds to activate
some other program (Like Console). The timer will fire
and fire and fire with no crash. Bring the program
foregound and CRASH. This is consistant with Shawn's
findings and the bad release code lines. And that was
the rub. The code wouldn't crash while running looking
at "TOP" or ObjectAlloc it would only crash after
bringing the LeakTest to the foregound. Even
correcting the code casuing the crash didn't "fix" the
problem. Because you would run the program then switch
to TOP or ObjectAlloc and watch the strings (and CFURL
objects) stack up. So I would still think there is
some sort of problem, go quit my program and deleve
into the code and be lost as to what to change because
it was about 15 lines of code. It didn't occure to me
to try and wrap the code in an AutoRelease Pool
because I was following all the rules that should have
made this stuff autorelease anyways so my next best
bet was to try to willy nilly release objects. And,
when I did that ObjectAlloc showed me that I wasn't
leaking anymore but now the application would crash
when it was brought to the foreground. Catch-22, leaky
app or app that crashes. It wasn't until last night
that on chance I switched to my code and noticed the
all the Strings dissappeard in ObjectAlloc. Then the
lightbulb went on and I fixed everything.
Thanks again Shawn, I'm done.
Yahoo! News - Today's headlines
http://news.yahoo.com
_______________________________________________
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.