Skip navigation.
 
mlRe: Memory leak in simple code?
FROM : Jason von Nieda
DATE : Thu Apr 07 20:33:27 2005

Thanks for the tips. That thread you linked is full of great
information. I'll try it this evening. I've already tried wrapping my
code in a NSAutoreleasePool and that didn't do it, so I'll try using the
non-convenience constructor and hope that takes care of it.

Jason

Matt Neuburg wrote:

>On Wed, 06 Apr 2005 23:45:07 -0500, Jason von Nieda <<email_removed>>
>said:

>

>>  // The next line is the one causing the leak. If I comment it out
>>the program does not leak and if I try to
>>  // release or autorelease "results" the program crashes.
>>  NSString *results = [NSString stringWithContentsOfURL:nsURL];
>>   
>>

>
>So don't do that. Do this:
>
>NSString* results = [[NSString alloc] initWithContentsOfURL:nsURL];
>[results release];
>
>In other words, to avoid the messy unknowns of convenience constructors,
>avoid convenience constructors.
>
>Nonetheless, NSTimers when the app is in the background need autorelease
>pools - in more places than you might suspect - if you are to avoid
>accumulating objects until the app comes to the front. (That, as I've said
>before, is the secret meaning of my .sig.) See, for example, this thread:
>
><http://www.cocoabuilder.com/archive/message/cocoa/2004/8/18/114873>
>
>m.
>

>

Related mailsAuthorDate
mlMemory leak in simple code? Jason von Nieda Apr 7, 06:45
mlRe: Memory leak in simple code? Johnny Deadman Apr 7, 06:59
mlRe: Memory leak in simple code? Johnny Deadman Apr 7, 07:02
mlRe: Memory leak in simple code? Jason von Nieda Apr 7, 16:51
mlRe: Memory leak in simple code? Matt Neuburg Apr 7, 18:49
mlRe: Memory leak in simple code? Shawn Erickson Apr 7, 19:37
mlRe: Memory leak in simple code? Shawn Erickson Apr 7, 20:16
mlRe: Memory leak in simple code? Jason von Nieda Apr 7, 20:33