tag:robotlegs.tenderapp.com,2009-10-18:/discussions/problems/608-robotlegs-garbage-collectionRobotlegs: Discussion 2012-06-29T14:58:18Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/169078522012-06-26T17:06:34Z2012-06-26T17:06:34ZRobotlegs & Garbage Collection<div><p>Hello,</p>
<p>Are you sure that GC has run? GC only runs when the Flash Player
needs more memory than is currently allocated. You may find that
the view component is destroyed quite some time after it is removed
from stage.</p>
<p>Robotlegs cleans up view and mediator reference automatically,
so it's unlikely that the framework is holding on to your
component. Are you using a profiler to observe the component
reference count?</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/169078522012-06-26T18:08:25Z2012-06-26T18:08:25ZRobotlegs & Garbage Collection<div><p>Hi Shaun,</p>
<p>Thanks for the reply.</p>
<p>Yes, the GC has run because I am manually running it from the
profiler.</p>
<p>If I remove the mediator mapping from the context and then
switch the state manually, it gets removed from memory when I run
GC.</p>
<p>It is very odd because there should be absolutely no references
keeping it in memory. What I will do is make an extremely simple
application and see if the issue is still happening with just a
basic example. If it is, then I will post the project on here and
see if other people experience it.</p></div>Paul Cotterelltag:robotlegs.tenderapp.com,2009-10-18:Comment/169078522012-06-26T19:33:17Z2012-06-26T19:33:17ZRobotlegs & Garbage Collection<div><p>Howdy,</p>
<p>Just double checking: are you running RL1 or RL2?</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/169078522012-06-26T20:51:21Z2012-06-26T20:51:22ZRobotlegs & Garbage Collection<div><p>I am running 1.5.2</p></div>Paul Cotterelltag:robotlegs.tenderapp.com,2009-10-18:Comment/169078522012-06-28T09:12:17Z2012-06-28T09:22:04ZRobotlegs & Garbage Collection<div><blockquote>
<p>What I will do is make an extremely simple application and see
if the issue is still happening with just a basic example. If it
is, then I will post the project on here and see if other people
experience it.</p>
</blockquote>
<p>Are you still having problems? If the answer is yes, you’d
better attach your project or a simplified example reproducing the
issue. I’ll take a look at it.<br>
If you solved the problem, posting your solution may help others
struggling with similar problems :)</p>
<p>As Shaun said: „GC only runs when the Flash Player needs
more memory than is currently allocated.“<br>
Have you tried to force the gc: “Run Garbage Collector”
in the profiler? Or inside your code, using System.gc() twice?</p>
<p>There are a couple of things that could prevent your View from
being gc-ed.<br>
In a way or another, something is holding a reference to your view
or one of its subcomponents.</p>
<p>A few questions for you:</p>
<ul>
<li>
<p>Are you adding event listeners to the view or subcomponents
directly instead of using the eventMap?</p>
</li>
<li>
<p>Are you setting useWeakReference to false when you map the
events?</p>
</li>
<li>
<p>Inside your View, are you using one of the following?</p>
</li>
</ul>
<blockquote>
<ul>
<li>
<p>setting buttonMode=true</p>
</li>
<li>
<p>setting focusEnabled=true</p>
</li>
<li>
<p>setting a styleName</p>
</li>
<li>
<p>using item renderers</p>
</li>
</ul>
</blockquote>
<ul>
<li>
<p>Is it a Flex or a pure as3 project?</p>
</li>
<li>
<p>Is it a mobile application?</p>
</li>
</ul>
<p>Without seeing the code, it’s hard to say if the issue
you’re encountering is caused by something listed above or if
it is something entirely different, and I would just keep
guessing.</p>
<p>Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/169078522012-06-29T09:59:34Z2012-06-29T09:59:36ZRobotlegs & Garbage Collection<div><p>Hi,</p>
<p>Sorry for the delay, I have attached a small example project
that has been tested using the profiler and there is definitely no
garbage collection. I ran the garbage collector manually and the
memory didn't reduce at all.</p>
<p>The application attached, when run, displays an image, click the
image and it moves to a state where the image component is
removed.</p>
<p>Let me know how you get on.</p>
<p>Kins Regards<br>
Paul</p></div>Paul Cotterelltag:robotlegs.tenderapp.com,2009-10-18:Comment/169078522012-06-29T11:49:13Z2012-06-29T12:01:42ZRobotlegs & Garbage Collection<div><p>Hi Paul,</p>
<p>I looked at your code.<br>
In MainUI.mxml you have this:</p>
<p><views:MiloUI includeIn="base"/></p>
<p>This will keep your component alive.</p>
<p>If you really want to destroy your component after changing
states, you can either<br>
set itemDestructionPolicy to auto:</p>
<p><strong><views:MiloUI includeIn="base"
itemDestructionPolicy="auto"/></strong></p>
<p>or<br>
you’ll have to add it through actionscript instead of mxml,
and then remove it manually when the state changes.</p>
<p>From Adobe’s documentation:<br>
Controlling caching of objects created in a view state<br>
„A change to a view state can cause Flex to create an object.
By default, after Flex creates the object, the object is cached
indefinitely, even after you switch to another view state. The item
is cached even if the destination view state excludes the
object.<br>
Use the itemDestructionPolicy attribute with the includeIn and
excludeFrom attributes configure Flex to completely destroy the
object when leaving a view state, including deleting it from the
cache. Typically it is more efficient to allow items to be cached
because it improves performance when switching back to the view
state that created the object, or to a view state that uses the
object. However your application might define a view state that is
rarely used, and you do not want to allocate memory for caching the
object.<br>
You can use the itemDestructionPolicy attribute on any object in
MXML that supports the includeIn and excludeFrom attributes. The
possible values for itemDestructionPolicy are never (default) and
auto.<br>
The value of never specifies that the object is cached
indefinitely. A value of auto means that the object is destroyed
when leaving a view state where the object exists.“</p>
<p>Please let us know if setting itemDestructionPolicy="auto"
solved your problem.</p>
<p>Cheers,<br>
Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/169078522012-06-29T14:05:30Z2012-06-29T14:05:31ZRobotlegs & Garbage Collection<div><p>Hi Ondina,</p>
<p>That worked perfectly.</p>
<p>Thanks very much for your help on this.</p>
<p>Kind Regards<br>
Paul</p></div>Paul Cotterelltag:robotlegs.tenderapp.com,2009-10-18:Comment/169078522012-06-29T14:58:17Z2012-06-29T14:58:17ZRobotlegs & Garbage Collection<div><p>Glad to hear it worked out well. You’re more than welcome,
Paul!</p></div>Ondina D.F.