discuss-gnustep
[Top][All Lists]
Advanced

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

Re: Two questions about NSView class


From: Fred Kiefer
Subject: Re: Two questions about NSView class
Date: Tue, 05 Aug 2008 08:54:34 +0200

Lets go through your code in detail:

NSText *texto = [[NSText alloc] initWithFrame: NSMakeRect(10,10,20,10)];
This creates an NSText object (Actually an NSTextView, as NSText is mostly just 
a placeholder for that class) and sets its retain count to 1.

[self addSubview: texto] ;
Internally this puts the NSTextView into the subview array and increases the 
retain count to 2.

RELEASE(texto);
This explicitly decreases the retain count to 1.

That way the text object is retained at the end of your code. Still you don't 
need to worry about that. As soon as it gets removed from the subclass array it 
will get deallocated and it is the responsibilty of the AppKit framework to 
take care of that.

In most cases the retain/release mechanism just works, you don't have to worry 
about it :-)

Cheers,
Fred

-------- Original-Nachricht --------
> Datum: Mon, 4 Aug 2008 11:15:57 -0700 (PDT)
> Von: "Germán André Arias Santiago" <germanandre304@yahoo.com>
> An: discuss-gnustep@gnu.org
> Betreff: Re: Two questions about NSView class

> Thanks Fred. My question is because the page 35 of manual (here
> http://www.gnustep.org/resources/documentation/Developer/Base/ProgrammingManual/manual_toc.html)
> say in the section 3.2.2 
> 
> "
> 
> 
> Exceptions
> 
> 
> In practice, the extra method call overhead should be avoided in
> performance
> critical areas and the instance variable should be set directly.  However
> in
> all other cases it has proven less error-prone in practice to consistently
> use
> the accessor.
> 
> 
> 
> There are certain situations in which the rule of having retains and
> releases
> be equal in a block should be violated.  For example, the standard
> implementation of a container class retains each object that is added
> to it, and releases it when it is removed, in a separate method.  In
> general you need to be careful in these cases that retains and releases
> match.     
> "
> OK, I want an app with a text tool, like in Cenon where you have a tool
> that let you add a text box in your document. I add the text with something
> like this
> 
> NSText *texto = [[NSText alloc] initWithFrame: NSMakeRect(10,10,20,10)]
> ;[self addSubview: texto] ;RELEASE(texto);
> Then, I don't know if I need release this after.
> 
> --- El mar 29-jul-08, Fred Kiefer <FredKiefer@gmx.de> escribió:
> De: Fred Kiefer <FredKiefer@gmx.de>
> Asunto: Re: Two questions about NSView class
> A: ""Germán Arias"" <germanandre304@yahoo.com>, discuss-gnustep@gnu.org
> Fecha: martes, 29 julio, 2008, 8:55 pm
> 
> Did you already get an answer to these questions?
> 
> First of all, in Objective-C you should not be concerned too much about
> memory.
> Normally things just happen correctly. When you remove a view from the
> hierarchy
> with removeSubView: then that view may or may not be freed. What happens
> is the
> it will get releases and if the retain count for the view drops to zero it
> gets
> deallocated.
> The method viewWillMoveToWindow: will be called in that process (as well
> as in
> many other cases), but in itself this hasn't much to do with memory
> management.
> 
> For standard GNUstep applications there is a memory usage display hidden
> in the
> info dialog. Just click on the image in that dialog.
> 
> Fred 
> 
> -------- Original-Nachricht --------
> > Datum: Thu, 24 Jul 2008 23:24:37 +0000 (UTC)
> > Von: "Germán Arias" <germanandre304@yahoo.com>
> > An: discuss-gnustep@gnu.org
> > Betreff: Two questions about NSView class
> 
> > OK, the methods -(void)removeSubview: and -(void)viewWillMoveToWindow:
> > release
> > the memory too, or just remove the objects from the receiver?, is there
> a
> > way to
> > see how my app handle the memory?
> > 
> > 
> > 
> > 
> > 
> > 
> > _______________________________________________
> > Discuss-gnustep mailing list
> > Discuss-gnustep@gnu.org
> > http://lists.gnu.org/mailman/listinfo/discuss-gnustep
> 
> -- 
> Psssst! Schon vom neuen GMX MultiMessenger gehört?
> Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger
> 
> 
> 
>      
> ____________________________________________________________________________________
> Yahoo! MTV Blog & Rock &gt;¡Cuéntanos tu historia, inspira una canción
> y gánate un viaje a los Premios MTV! Participa aquí
> http://mtvla.yahoo.com/

-- 
Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! 
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer




reply via email to

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