You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@flex.apache.org by bilbosax <wa...@comcast.net> on 2016/07/25 03:55:05 UTC

Question about Components, Garbage Collection, an CreationComplete

So I was wondering if there was a way by eliminating all references and using
garbage collection, that you could garbage collect a custom Component?

I have written a program with three major MXML files: The main application,
a database component, and an analysis component to display the data.  I
display these using three states in the application.  I use a database
button and analysis button in the main application to switch to the other
two states states, thus showing each of the components, and an exit button
in each component sends you back to the main application.  The problem is
that if I switch from the analysis component, back to the database component
to load more data, and then back to the analysis component, the creation
complete for the analysis has already fired and does not fire again when I
come back to the component.  I wondered if there was a way to reinstantiate
the components somehow so that they can collect the data that they need to
when you enter their respective states.

My first thought was to try and garbage collect the component, and then
perhaps it would be recreated when I came back to its state.  That seems
over complicated. Surely there is a more straight forward approach that I am
not familiar with?



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Question-about-Components-Garbage-Collection-an-CreationComplete-tp13041.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: Question about Components, Garbage Collection, an CreationComplete

Posted by jude <fl...@gmail.com>.
you could also listen for state change events and call the creation
complete event manually.

<s:SomeMXMLComponent stateChange="someComp.creationComplete(event)"
id="someComp" includeIn="someState" />

On Jul 25, 2016 1:46 AM, "Alex Harui" <ah...@adobe.com> wrote:



On 7/24/16, 8:55 PM, "bilbosax" <wa...@comcast.net> wrote:

>Surely there is a more straight forward approach that I am
>not familiar with?
>

Well, there is using a bit more ActionScript.  Instead of declaring an
MXML component in our MXML, instantiate it in ActionScript.

IOW, instead of:

<s:Application>
  <s:Button click-"currentState='someState' />
  <s:SomeMXMLComponent id="someComp" includeIn="someState" />
</s:Application>

You can do something like this:

<s:Application>
  <s:Button click-"currentState='someState'; someComp = new
SomeMXMLComponent(); addElement(someComp);" />
</s:Application>


Some other code that switches away from someState would call
removeElement(someComp) and someComp = null;

As long as SomeMXMLComp doesn't have any other references to it, it would
go away.

HTH,
-Alex

Re: Question about Components, Garbage Collection, an CreationComplete

Posted by Alex Harui <ah...@adobe.com>.

On 7/25/16, 10:57 AM, "bilbosax" <wa...@comcast.net> wrote:

>When looking at memory useage in the profiler, is there a size that you
>think
>a program should never exceed for AIR to be able to handle it efficiently?

I don't have a number that I use, plus I haven't really looked at recent
AIR versions.  Flash/AIR used to start having issues at 500MB, but I
expect that number could be higher these days.  On the other hand, if your
customer happens to see your app in Task Manager and it is the #1 user of
memory, you might hear about it...

-Alex


Re: Question about Components, Garbage Collection, an CreationComplete

Posted by bilbosax <wa...@comcast.net>.
When looking at memory useage in the profiler, is there a size that you think
a program should never exceed for AIR to be able to handle it efficiently?



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Question-about-Components-Garbage-Collection-an-CreationComplete-tp13041p13064.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: Question about Components, Garbage Collection, an CreationComplete

Posted by Alex Harui <ah...@adobe.com>.
IMO, there is no one right answer.  Usually, these MXML components are
heavy and slow and the UI freezes during instantiation.  The point of
states is to retain these initialized components and only flip a few
properties in it when re-using it.  That's a reason we recycle item
renderers as well.

However, there is a cost to trying to "revert" an instance back to some
"safe" set of properties since that also takes time plus you sometimes
forget to undo something, so it might just be easier to toss them and
create new ones.  

That said, using Model/View, MVC or other patterns where the View operates
on a separable data model is my recommendation.  Usually it is the
instantiation of the UI widgets that is so costly, so you can re-use the
View, but just assign it a different model instance.

HTH,
-Alex

On 7/25/16, 10:33 AM, "bilbosax" <wa...@comcast.net> wrote:

>Thank you Alex.  I have followed you in the Flex development world
>starting
>back in 2009 when it first came up on my radar screen so I know how much
>you
>understand all of this material and am grateful for all of your input.
>Since I just dabble in this, I am curious as to what you think is the
>proper
>way to handle this situation.  Do you think it is better to close out the
>component, and then to recreate it each time I need it?  Or do you feel it
>is better to just listen for a state change to reset all of the value in
>my
>component, and to just keep the one component and use it over and over?
>
>
>
>--
>View this message in context:
>http://apache-flex-users.2333346.n4.nabble.com/Question-about-Components-G
>arbage-Collection-an-CreationComplete-tp13041p13059.html
>Sent from the Apache Flex Users mailing list archive at Nabble.com.


Re: Question about Components, Garbage Collection, an CreationComplete

Posted by bilbosax <wa...@comcast.net>.
Thank you Alex.  I have followed you in the Flex development world starting
back in 2009 when it first came up on my radar screen so I know how much you
understand all of this material and am grateful for all of your input. 
Since I just dabble in this, I am curious as to what you think is the proper
way to handle this situation.  Do you think it is better to close out the
component, and then to recreate it each time I need it?  Or do you feel it
is better to just listen for a state change to reset all of the value in my
component, and to just keep the one component and use it over and over?



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Question-about-Components-Garbage-Collection-an-CreationComplete-tp13041p13059.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: Question about Components, Garbage Collection, an CreationComplete

Posted by bilbosax <wa...@comcast.net>.
Thank you Alex.  I have followed you in the Flex development world starting
back in 2009 when it first came up on my radar screen so I know how much you
understand all of this material and am grateful for all of your input. 
Since I just dabble in this, I am curious as to what you think is the proper
way to handle this situation.  Do you think it is better to close out the
component, and then to recreate it each time I need it?  Or do you feel it
is better to just listen for a state change to reset all of the value in my
component, and to just keep the one component and use it over and over?



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Question-about-Components-Garbage-Collection-an-CreationComplete-tp13041p13060.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: Question about Components, Garbage Collection, an CreationComplete

Posted by Alex Harui <ah...@adobe.com>.

On 7/24/16, 8:55 PM, "bilbosax" <wa...@comcast.net> wrote:

>Surely there is a more straight forward approach that I am
>not familiar with?
>

Well, there is using a bit more ActionScript.  Instead of declaring an
MXML component in our MXML, instantiate it in ActionScript.

IOW, instead of:

<s:Application>
  <s:Button click-"currentState='someState' />
  <s:SomeMXMLComponent id="someComp" includeIn="someState" />
</s:Application>

You can do something like this:

<s:Application>
  <s:Button click-"currentState='someState'; someComp = new
SomeMXMLComponent(); addElement(someComp);" />
</s:Application>


Some other code that switches away from someState would call
removeElement(someComp) and someComp = null;

As long as SomeMXMLComp doesn't have any other references to it, it would
go away.

HTH,
-Alex