[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
> <richard.frith-macdonald@theengagehub.com>:
>
>
>
>> On 16 Mar 2018, at 15:18, amon <amon@vnl.com> 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:
>
> CREATE_AUTORELEASE_POOL(pool);
> 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
CREATE_AUTORELEASE_POOL(pool);
obj = [Foo new];
// zone used = n+m bytes
[obj release];
DESTROY(pool);
// zone used = n bytes.
This should result in the expected behaviour.
- Re: GNUstep and valgrind, (continued)
- Re: GNUstep and valgrind, amon, 2018/03/13
- Re: GNUstep and valgrind, Richard Frith-Macdonald, 2018/03/14
- Re: GNUstep and valgrind, amon, 2018/03/13
- Re: GNUstep and valgrind, amon, 2018/03/14
- Re: GNUstep and valgrind, amon, 2018/03/16
- Re: GNUstep and valgrind, Richard Frith-Macdonald, 2018/03/16
- Re: GNUstep and valgrind,
Fred Kiefer <=
- Re: GNUstep and valgrind, Richard Frith-Macdonald, 2018/03/16
- Re: GNUstep and valgrind, Richard Frith-Macdonald, 2018/03/16
- Re: GNUstep and valgrind, Fred Kiefer, 2018/03/16
- Re: GNUstep and valgrind, Fred Kiefer, 2018/03/16
- Re: GNUstep and valgrind, Richard Frith-Macdonald, 2018/03/16
- Re: GNUstep and valgrind, amon, 2018/03/16
- Re: GNUstep and valgrind, amon, 2018/03/17
- Re: GNUstep and valgrind, Ivan Vučica, 2018/03/17
- Re: GNUstep and valgrind, amon, 2018/03/17
- Re: GNUstep and valgrind, Fred Kiefer, 2018/03/18