discuss-gnustep
[Top][All Lists]
Advanced

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

Re: strange crasher that puzzles me


From: Sebastian Reitenbach
Subject: Re: strange crasher that puzzles me
Date: Wed, 1 Apr 2009 07:26:53 +0200
User-agent: KMail/1.9.9

On Tuesday 31 March 2009 17:40:23 David Chisnall wrote:
> On 31 Mar 2009, at 16:12, Sebastian Reitenbach wrote:
> > Are there any easy rules of thumb to follow, any good documentation
> > about
> > memory-management in objective-c for the "beginner" like me?
> > So if anyone remembers a document that made him think after reading:
> > "ah,
> > thats the way how it works" then you could make me happy pointing me
> > to such
> > a document ;)
>
> I wrote a short introduction here:
>
> http://etoileos.com/dev/docs/languages/obj-c/
>
> Simple rules of thumb:
>
> - Any object created with +alloc or +new is retained and must be -
> release'd when you're done with it.  The same is true of objects
> created with -copy and -copyWithZone:
>
> - Any object you get by any other means is autoreleased and you should
> not assume that the pointer will be valid beyond the current
> function / method.
>
> - If you want to keep a pointer to an object, send it a -retain
> message (unless you just created it with +alloc or +new).
>
> - When you are done with an object, send it a -release message.
>
> - If you need to return an object, but don't want to keep a reference
> to it, send it an -autorelease message.
>
> - Never assume that an object you have sent a -release or -autorelease
> message to is still valid.  Never send it any other messages.  Only
> ever use autoreleased objects return values for functions or methods.
>
> - Use the ASSIGN() macro when assigning an object to an ivar, with
> these exceptions:
>       - You just created the object, using -copy, +new, or +alloc.
>       - The object has a pointer to this object (this would create a loop).
>
> - Always implement -dealloc in your objects if they have any object
> ivars, but never call it directly.
>
> I think this covers pretty much everything,
thanks a lot for this explanation, exactly what I was looking for.
Also thanks the others suggesting further documentation, will take a look 
there anyways.

kind regards
Sebastian



>
> David






reply via email to

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