Perhaps what the doc writer had in mind is that if you have a function
which does a lengthy computation, you could free up memory in the middle
of the computation by nulling a local variable holding a reference. But
I'm pretty sure that nulling it at the end of the function wouldn't
accomplish anything because it is immediately going out of scope, and
this frees the reference.

Gary, can you comment?

- Gordon


-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of JesterXL
Sent: Tuesday, February 21, 2006 5:09 PM
To: [email protected]
Subject: Re: [flexcoders] Re: Object cleanup and memory usage "Best
Practices" (2.0b1)

That's not what the documentation says for optimizing memory for Flash
Lite 
2, and that is the only thing I'm going off of.  Does that apply only to
the 
Flash Lite 2 player specifically?  It acknowledges that locals go out of

scope but that you should still null them:

"Although you cannot control how and when Flash Lite performs garbage 
collection, you can still free unneeded memory deliberately. For a
timeline 
or global variables, you can use the delete statement to free the memory

that ActionScript objects use. For local variables--for example, a
variable 
defined within a function definition--you can't use the delete statement
to 
free an object's memory, but you can set to null the variable that 
references the object. This frees the memory that the object uses,
provided 
there are no other references to that object."

I'm guessing maybe I read that wrong or mis-understood what they said?



----- Original Message ----- 
From: "Gordon Smith" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Tuesday, February 21, 2006 4:33 PM
Subject: RE: [flexcoders] Re: Object cleanup and memory usage "Best 
Practices" (2.0b1)


>    // now you're saying I should null my locals...?
>    oBtn=null;

There is no reason to do this. When createChildren() returns, its locals
go out of scope and oBtn no longer holds a reference to the Button
instance. So nulling it doesn't accomplish anything. The Button instance
doesn't get garbage collected because its parent now has a reference to
it, due to addChild().

- Gordon


-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of JesterXL
Sent: Monday, February 20, 2006 3:13 PM
To: [email protected]
Subject: Re: [flexcoders] Re: Object cleanup and memory usage "Best
Practices" (2.0b1)

That's striaight, yo.  What you have is perfect syntactically.

As for functions, yeah, AS3 solved it.  In AS2, we eventually all
started
using mx.utils.Delegate as of the Flash MX 2004 7.2 update which
included
the class.  Joey Lott had Proxy... there were tons of derivatives would
all
basically returned a function that called itself in the correct scope.

AS3 now calls functions in the scope they are defined, not invoked, so
all
is well (no need for Delegate anymore).

----- Original Message ----- 
From: "thunderstumpgesatwork" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Monday, February 20, 2006 6:06 PM
Subject: [flexcoders] Re: Object cleanup and memory usage "Best
Practices"
(2.0b1)


OK, thanks.

That reading and your examples cleared things up. I never declare
functions dynamically like these examples (they're always methods
defined on a class), and I definitely never nest function creation.

One thing I do often do (for instance in a "createChildren" function
is create a local variable (to be used as a child object), add some
event listener, and then add it to the parent. Is code like this ok?

class foo extends HBox
{
function createChildren():void
{
    var oBtn:Button = new Button();
    oBtn.addEventListener("click",onBtnClick);
    this.addChild(oBtn);

    // now you're saying I should null my locals...?
    oBtn=null;
}
function onBtnClick(event:MouseEvent):void
{
   // do whatever
}
} // end class foo

I know for ActionScript 3 there were some changes to do with adding
event listeners, and I've never had any problems with the scope of my
functions; they always seem to have the scope of the object they're
defined in.

thanks,
Thunder

--- In [email protected], "JesterXL" <[EMAIL PROTECTED]> wrote:
>
> Negative, local variables are good, and optimized in Flash Player 7.
 Use
> them.  This discussion is getting more boilerplate code than it
should, but
> if you want to know the details, I can elaborate.
>
> Back in Flash Player 6, MovieClips got the option to have event
handlers
> attached to them.  That is also back when functions were executed in
the
> scope they were defined when called that way.  Thus:
>
> function myOnPress()
> {
> }
>
> my_mc.onPress = myOnPress;
>
> the myOnPress function would run scoped to my_mc, not in relation to
the
> class myOnPress was defined.  This was more pronounced in data
classes like
> XML:
>
> function init()
> {
>     my_xml = new XML();
>     my_xml.onLoad = myOnLoad;
>     my_xml.load("some.xml");
> }
>
> The myOnLoad function would run in the scope of XML, not in the
scope of the
> class.  Various tricks were used to steer the scope back to the class.
> http://www.gskinner.com/blog/archives/000069.html
>
> Again, I am not suggesting to not use local variables; quite the
opposite to
> use them.  I highly suggest you do not do what the above URL suggests.
>
> As for delete; don't know.
>
> ----- Original Message ----- 
> From: "thunderstumpgesatwork" <[EMAIL PROTECTED]>
> To: <[email protected]>
> Sent: Monday, February 20, 2006 1:50 PM
> Subject: [flexcoders] Re: Object cleanup and memory usage "Best
Practices"
> (2.0b1)
>
>
> Let me get this straight... did you suggest not to use local
variables?
>
> "My suggestion; don't use it.  And when you do (meaning you create
> local variables)"
>
> What do you suggest instead? I'm not making every variable a member
> variable...
>
> Thanks for the info on the Activation object. I will null out my local
> variables at the end of the function, but it sure seems weird to
> suggest not to use them at all!
>
> Also, seems like a pretty bad shortcoming not to have a deconstructor
> or finalizer or anything. One last question, does calling delete on an
> object release any Activation objects created for it?
>
> thanks,
> Thunder
>
> --- In [email protected], "JesterXL" <jesterxl@> wrote:
> >
> > Nope.  Some people used onUnload for MovieClips, but I wouldn't
> touch that
> > method with a 10ft-pole.
> >
> > From the MM docs:
> >
> > "The Activation object. (A temporary object that is automatically
> created
> > when a function is called that holds the local variables called in
the
> > function.)"
> >
> > The Activation Object can actually live on long after the function
has
> > finished being removed from the stack.  This is an ethereal plane
> that is
> > useful for getting around scope challengs people had in the early
> days of
> > ActionScript 2 development.
> >
> > My suggestion; don't use it.  And when you do (meaning you create
local
> > variables), set them to null at the end of the function.
> >
> > function cow()
> > {
> >     var a:String = "moo";
> >     a = null;
> > }
> >
> > ----- Original Message ----- 
> > From: "thunderstumpgesatwork" <thunder.stumpges@>
> > To: <[email protected]>
> > Sent: Monday, February 20, 2006 12:56 PM
> > Subject: [flexcoders] Re: Object cleanup and memory usage "Best
> Practices"
> > (2.0b1)
> >
> >
> > Thanks for the tips. I a couple questions about your comments.
> >
> > - question regarding number 3,5... is there a deconstructor in
> > ActionScript that I can place cleanup code?
> >
> > - number 6 what do you mean by activation object? Do you mean
> > RemoteObject? if so, could you please explain how to clean it up
> > properly, as I need to use it, and there was no documentation on how
> > to clean it up.
> >
> > Thanks!
> >
> > --- In [email protected], "JesterXL" <jesterxl@> wrote:
> > >
> > > 6 rules of thumb:
> > >
> > > 1. never trust an alpha for benchmarking
> > >
> > > 2. never trust a beta for benchmarking
> > >
> > > 3. if it's a member variable, delete it:
> > >
> > > delete myVar;
> > >
> > > 4. if it's a local variable, null it at the end of the function:
> > >
> > > function cow()
> > > {
> > >     var a:String = "";
> > >     a += "one";
> > >     a += "two";
> > >     a = null;
> > > }
> > >
> > > 5. remove your event listeners before destroying the objects you
> > registered
> > > with
> > >
> > > 6. do not use the activation object unless you know how to clear
it
> > later
> > > (most people I've seen in AS2 never do, so try not to use it
period).
> > > Example is xml.onLoad where the xml is created as a local variable
> in a
> > > function.  It'll live on even though it's a local variable.
> > >
> > > ----- Original Message ----- 
> > > From: "thunderstumpgesatwork" <thunder.stumpges@>
> > > To: <[email protected]>
> > > Sent: Saturday, February 18, 2006 7:02 PM
> > > Subject: [flexcoders] Object cleanup and memory usage "Best
Practices"
> > > (2.0b1)
> > >
> > >
> > > Hi all,
> > >
> > > I've been coding in Flex now for a few months (basically since
the 2.0
> > > Alpha came out) and I've been having a heck of a problem with
memory
> > > leaks.
> > >
> > > I was curious if there's any kind of rules or best practices to
use
> > > for cleaning up AS objects (destructors? finalize()? or other?)
This
> > > is especially pertinent because I am using lists/hash's, charts,
and
> > > RPC Services.
> > >
> > > I couldn't really find any documentation regarding clean-up and
memory
> > > leaks. Does anyone out there have any experiences/knowledge to
share?
> > >
> > > Below, I'll outline my architecture, and note that I have no
> > > cleanup/de-construction code right now at all, other than setting
> > > variable references to new objects or null. Sorry it's pretty
long, so
> > > if you want to stop reading here and provide any ideas you have,
feel
> > > free =)
> > >
> > > thanks,
> > > Thunder
> > > _____________
> > >
> > >
> > > Basically I am running dynamic DB queries through a singleton
> > > RemoteObject called by a "ChartResults" class that holds the
results
> > > (e4x XML) of the query and metadata info related to it. I have
> > > employed the "Asynchronous Completion Token" documented approach
to
> > > allow the ChartResults classes to pick out only their calls from
the
> > > singleton R.O.
> > > Is this detrimental to performance if there are anywhere from
4-10 SQL
> > > calls possibly going through the one RemoteObject? (note - that's
an
> > > upper limit during initial startup only)
> > >
> > > The ChartResults class caches information as it is retrieved
from the
> > > results (often after performing filtering/sorting, etc).
> > >
> > > When a new query result comes in, the I clear all the cache
> > > items by setting the hash objects or Array to null or new
Object/Array
> > > respectively.
> > >
> > > 1 - Does setting a property referencing a Collection to null also
> > > release the source Array held in it?
> > >
> > > 2 - Do I also need to set each item in the Array to null?
> > >
> > > 3 - If a hash Object had many different XMLList properties cached,
> > > do I need to iterate and null all these properties using
> introspection?
> > >
> > > Also, on the Chart side, I have been deleting the series array and
> > > creating a new one when re-populating the chart (if it is showing
> > > entirely new/different data).
> > >
> > > 4 - Do I need to do any cleanup of the series items maybe?
> > >
> > > 5 - Are the Series getting cleaned up and releasing their
dataProvider
> > > objects?
> > >
> > > Somewhere I am leaking memory badly as the number of chart queries
> > > goes up and up...
> > >
> > > Thanks again!
> > > Thunder
> > >
> > >
> > >
> > >
> > >
> > >
> > > --
> > > Flexcoders Mailing List
> > > FAQ:
http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> > > Search Archives:
> > http://www.mail-archive.com/flexcoders%40yahoogroups.com
> > > Yahoo! Groups Links
> > >
> >
> >
> >
> >
> >
> >
> > --
> > Flexcoders Mailing List
> > FAQ:
http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> > Search Archives:
> http://www.mail-archive.com/flexcoders%40yahoogroups.com
> > Yahoo! Groups Links
> >
>
>
>
>
>
>
> --
> Flexcoders Mailing List
> FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> Search Archives:
http://www.mail-archive.com/flexcoders%40yahoogroups.com
> Yahoo! Groups Links
>







--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives:
http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links







--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives:
http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links








--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives:
http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links







--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives:
http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links



 




--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to