discuss-gnustep
[Top][All Lists]
Advanced

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

Re: GNUstep and valgrind


From: H. Nikolaus Schaller
Subject: Re: GNUstep and valgrind
Date: Tue, 20 Mar 2018 08:48:19 +0100

> Am 20.03.2018 um 08:33 schrieb Andreas Fink <address@hidden>:
> 
> 
> 
>> On 20 Mar 2018, at 08:22, H. Nikolaus Schaller <address@hidden> wrote:
>> 
>> 
>>> Am 20.03.2018 um 08:11 schrieb Andreas Fink <address@hidden>:
>>> 
>>> 
>>> You never call "release" on a autorelease pool.
>> 
>> Not "never": 
>> https://developer.apple.com/documentation/foundation/nsautoreleasepool
>> 
>> Using drain over release is a "should" not a "must".
> 
> 
> 
> Well if you use garbage collection drain is not the same as release.

Exactly.

> Using garbage collection however is highly depreciated.

And without, you (still) can use release and they are the same.

> Every OS X app sample code or other source I have seen always uses drain.

It can be understood historically:

https://developer.apple.com/documentation/foundation/nsautoreleasepool/1520553-drain?language=objc

tells that -drain was introduced in OS X 10.4. So all code and examples written 
before (NeXTstep, OpenStep, 10.0-10.3),
must have used -release.

So -drain was only introduced to support GC, which itself isn't used any more 
today.

But it is a long time since these ages, so almost every example you can find 
today has been changed to use -drain.
Internet is a lot of copy&paste and (contrary to some urban legend) forgets a 
lot of things.

> You might be right that drain is the same as release in some cases however. 
> Calling drain is the recommended action.

Well, not really. Refer to the section on Garbage collection in the 
nsautoreleasepool documentation.

It mainly seems to say:
1. for GC you don't need an ARP
2. if you write a framework that should work with GC *and* ARP you should use it
3. using -drain is a hint for the GC, contrary to -release 

I interpret this as if you never want to use GC you can freely choose between 
both and there is no specific recommendation.

> How GnuStep has implemented drain vs. release I would have to check. But if 
> you follow the Apple documentation, the GnuStep implementation should follow 
> along (with a few exceptions which are not implemented [yet]). So calling 
> drain would be a safe bet.

Indeed. It is safer. Unless you have code that you still want to compile on <OS 
X 10.4 systems. Then, release is safer because it still works on 10.13.

So it seems to be impossible to find a general answer :(

Anyways, this does not help the original leak issue.




reply via email to

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