gnustep-dev
[Top][All Lists]
Advanced

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

Re: DO and "leaked" connection object


From: Riccardo Mottola
Subject: Re: DO and "leaked" connection object
Date: Tue, 05 Feb 2013 14:30:58 +0100
User-agent: Mozilla/5.0 (X11; NetBSD i386; rv:17.0) Gecko/20130204 Thunderbird/17.0.2

Hi,

On 02/05/13 11:06, Richard Frith-Macdonald wrote:
The rules here are nothing special ... you need to retain an object until you 
no longer want to use it.
In this case you say you want to keep the connection until the program ends (so 
you can get messages from other apps), so the correct behavior is to keep the 
object retained until the program ends ... which is what your code does.
The compiler is warning you because it sees the variable go out of scope (at 
which point it becomes impossible for you to release it), but that's harmless 
because you never want to release it.

That being said, the compiler is warning you about a bad practice ... you 
really should use a global variable or instance variable.
Not only will doing that avoid the compiler warning, it will also allow you to 
release the connection explicitly on or before program termination.

I like to invalidate and release connections immediately before shutdown, in 
order to ensure that messages from other apps don't arrive while in the process 
of shutting down.  If your app has a complicated clean-up process when it shuts 
down, an incoming message at that point could mess things up, so it's simpler 
to stop accepting messages and then do other cleanup.
Thank you, that is what I supposed and wanted confirmation on. I was just wondering out there that all example code looks about similar (our own dodges this because it puts everything in main() so not explicitly releasing is not so obvious http://www.gnustep.org/resources/documentation/Developer/Base/ProgrammingManual/manual_7.html) I was guessing about some strange practice.

The clearest thing is probably to make it an ivar and then in "dealloc" issue an invalidate first and a release then?

Thank you,
   Riccardo



reply via email to

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