tag:robotlegs.tenderapp.com,2009-10-18:/discussions/suggestions/14-easily-disposable-contextRobotlegs: Discussion 2013-04-28T10:35:42Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/10957532010-02-25T10:17:19Z2010-02-25T10:17:19ZEasily disposable context<div><p>Hello!</p>
<p>The general approach is to dispatch a SHUTDOWN event on your
modules's IEventDisptcher - that way, any interested parties can
clean themselves up. When shutdown has completed, fire off a
SHUTDOWN_COMPLETE event - that way your shell can determine that
the module has been properly cleaned up.</p>
<p>You can dispatch the initial SHUTDOWN event from the outside by
dispatching it directly on the context itself (the context happens
to be the IEventDispatcher for itself), so you can tell a module to
shutdown from your shell.</p>
<p>Does that make any sense?</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/10957532010-02-25T10:27:47Z2010-02-25T10:27:47ZEasily disposable context<div><p>Helle Shaun !</p>
<p>Thanks for your fast answer !<br>
In fact, I allready use these SHUDOWN and SHUTDOWN_COMPLETE events,
but I was thinking of a context self disposing itself with a single
function, without having to code it manually (like unmapping all
commands that have been mapped, deleting and unmapping all actors,
the same for mediators), made automatically by RobotLegs without
having to write it mannualy, risking to forget things.<br>
So the context itself would be responsible to make the whole
cleanup, and it would be without having to code anything. The only
thing that would have to be coded are more manual things (disposing
model contents for instance) independent from the framework.<br>
So when you would like to unload a module, you would still dispatch
the SHUTDOWN event, each parties interested would cleanup itself
but ONLY for non framework things (like a bitmapdata model would
dispose the bitmap data for instance, but not unmap itself from
robotlegs), and once this done, a "dispose" methode would be called
on the context, cleaning all framework things like mappings.<br>
Is this something that makes sense or am I thinking wrong?<br>
Anyway, thanks again for your great job, I really love using
Robotlegs daily !!!</p></div>combes.benjamintag:robotlegs.tenderapp.com,2009-10-18:Comment/10957532010-02-25T11:02:05Z2010-02-25T11:02:05ZEasily disposable context<div><p>If your objects have been designed well, you should be able to
do this (wherever you constructed the context):</p>
<pre>
context = null;
</pre>
<p>And the Garbage Collector should take care of the rest. There is
no need to explicitly unmap things - in terms of framework classes,
everything has been designed with GC in mind. Bear in mind that GC
will only run when the Flash Player actually needs more memory.</p>
<p>What I'm getting at is that you should use SHUTDOWN to trigger
any custom cleanup (usually pretty minimal), and then just drop the
reference to the context. There are no statics or Singletons that
will hold on to the Robotlegs objects.</p>
<p>I recommend trying it out with the Flash Builder profiler:</p>
<p>Create a Context as usual. Make it do all kinds of memory
consuming things. Then just drop the reference to the context, and
instantiate a new context (or a new memory consumptive object). Do
this a couple of times and see what hangs around. If all goes well,
nothing should survive.</p></div>Shaun Smith