[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GNUstep and valgrind

From: Fred Kiefer
Subject: Re: GNUstep and valgrind
Date: Fri, 16 Mar 2018 16:44:00 +0100

> Am 16.03.2018 um 16:32 schrieb Richard Frith-Macdonald <address@hidden>:
>> On 16 Mar 2018, at 15:18, amon <address@hidden> wrote:
>>           [arglist release];
>> arglist = [[[NSMutableString stringWithCString: [cmdline cString]]
>>              componentsSeparatedByString: DELIM] retain];
>> This happens inside an init. arglist is release by the dealloc
>> method. However, NSMutableString insists on making it autoreleased.
>> I want to make it not do that. 
> Portable GNUstep code would look like this:
> ASSIGN(arglist, [[[NSMutableString stringWithCString: [cmdline cString]] 
> componentsSeparatedByString: DELIM]);
> DESTROY(pool);
> with no wasted/leaked memory.

I have to disagree. This will get rid of the intermediate NSMutableString but 
later on when the surrounding Foo object gets released the arglist ivar will 
get released as well, but the component strings in that array will still remain 
in what ever autorelease pool is active at that time and will only get freed 
when that pool is cleaned up. Or at least this is my understanding of 
autorelease pools.

In the given example this could be resolved by adding another auto release pool:

        // zone used = n bytes
        obj = [Foo new];
        // zone used = n+m bytes
        [obj release];
        // zone used = n bytes.

This should result in the expected behaviour.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]