tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/829-problem-modular-context-being-cached-by-main-applicationRobotlegs: Discussion 2018-10-18T16:35:36Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/138600462012-02-21T11:04:55Z2012-02-21T11:04:56ZProblem Modular Context Being Cached by Main Application<div><p>Hello,</p>
<p>I am writing here cause I haven't been unable to find a way to
fix the problem I have encoutered.</p>
<p>Here is an explanation :</p>
<p>I have a main project using swf file. Then I have small games
using RL as well but implemented as Modules. Those small games can
be run multiple times, not at the same time, but you get in, you
close it, then come back to it 10 sec later.</p>
<p>Here is the issue : Every thing is destroyed properly, we
dispose of the small game context, and destroy the view that holds
the small game in the main app, but when I trigger the small game
later on, like 5 sec later, it's like the main app has cached the
small game context and instead of loading a new one (cause the
small games swf files are loaded from a server), it's like using
the one that is supposed to have been destroyed.</p>
<p>I can see that cause I have created a static variable in the
modular small game, I increment it each time I create a new
instance of this module, and it keeps going up, so it's deffo using
the same context again. I don't want that obviously, and I was
wondering if any one had an idea how to fix that ?</p>
<p>I encountered the same issue with another game, this one was
duplicated 12 times on the server but with different assets in, but
because the contexts were the same names, it was always loading the
same one, so we fixed it by using different context names, which
led us to create 12 different projects :/</p>
<p>But this time, I can't do it, cause we want the same small game,
but each time like you're accessing it for the first time.</p>
<p>Thank you and sorry for my English</p></div>Christophetag:robotlegs.tenderapp.com,2009-10-18:Comment/138600462012-02-21T11:38:46Z2012-02-21T11:38:46ZProblem Modular Context Being Cached by Main Application<div><p>Hi Christophe,</p>
<p>do you have access to the flex debugger?</p>
<p>I'm wondering whether you've tried to chase what is referencing
the context?</p>
<p>If you're loading the small games with a Loader, are you using
the Loader's unloadAndStop() method? I know there used to be
problems with complete unloading of anything containing sound, but
I'm sure that has been fixed a long time ago.</p>
<p>I'm sure we can help you find out where the reference is.</p>
<p>Which version of modular utilities are you using?</p>
<p>Thanks,</p>
<p>Stray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/138600462012-02-21T11:41:30Z2012-02-21T11:42:28ZProblem Modular Context Being Cached by Main Application<div><p>My guess is this has nothing to do with RL, but I'm definitely
no expert on RL modules, so it could be I'm wrong.</p>
<p>You write</p>
<blockquote>
<p>we dispose of the small game context, and destroy the view that
holds the small game in the main app</p>
</blockquote>
<p>but do you unload the module's .swf?I'm guessing that's
what doesn't get GC'd</p>
<p>And</p>
<blockquote>
<p>I can see that cause I have created a static variable in the
modular small game, I increment it each time I create a new
instance of this module, and it keeps going up, so it's deffo using
the same context again.</p>
</blockquote>
<p>Doesn't mean that it's using the same context again, just that
the class definition itself has not been removed from memory.</p></div>creynderstag:robotlegs.tenderapp.com,2009-10-18:Comment/138600462012-02-21T12:09:24Z2012-02-21T12:09:25ZProblem Modular Context Being Cached by Main Application<div><p>Hey thanks for the so fast reply, I wasn't expecting any thing
before tomorrow hehe.</p>
<p>I have added the unloadAndStop method to my loader, but it
doesn't change any thing.</p>
<p>I have actually access to the Flex Debugger. I am casting the
swf file loaded as a sprite for practical reasons, then i assign it
to a IModule variable to inject the injector of the main swf file.
I properly dispose this IModule variable then assign null to
it.</p>
<p>m_moduleRef.parentInjector = null;<br>
m_moduleRef.dispose();<br>
m_moduleRef = null</p>
<p>Maybe something I should have mentionned guys is there's
communication between this module and the main swf file, and
another reason I can see it's using the same context is that at the
beginning I send a request from the game to the main sw file and
when I get the response, I display the state of the game, and it
displays it twice....I checked my game twice and the communication
and it's definitely not sending the response twice.</p>
<p>To reformulate, it's like it's using a new context and the
previous one.</p>
<p>I am using RL 1.5.2 , and the modular thing...I don't know to be
honest, I will compare joelhooks and Stray zip to mine to see which
one I'm using, then come back to you</p></div>Christophetag:robotlegs.tenderapp.com,2009-10-18:Comment/138600462012-02-21T12:13:46Z2012-02-21T12:13:47ZProblem Modular Context Being Cached by Main Application<div><p>I am using the modular utilities from Joel Hooks</p></div>Christophetag:robotlegs.tenderapp.com,2009-10-18:Comment/138600462012-02-21T12:39:17Z2012-02-21T12:39:17ZProblem Modular Context Being Cached by Main Application<div><p>There was an issue with the moduleCommandMap not automatically
being unmapped when the module is disposed - could that be the
problem?</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/138600462012-02-21T12:52:31Z2012-02-21T12:52:33ZProblem Modular Context Being Cached by Main Application<div><p>Stray, I checked the dispose function used and there are those 2
lines :</p>
<pre>
<code> _moduleCommandMap.unmapEvents();
_moduleCommandMap = null;</code>
</pre>
<p>So I assume the moduleCommandMap is properly unmapped when the
module is disposed.</p></div>Christophetag:robotlegs.tenderapp.com,2009-10-18:Comment/138600462012-02-21T12:55:17Z2012-02-21T12:55:17ZProblem Modular Context Being Cached by Main Application<div><p>Hrm. In that case I'd say the Flex debugger is your best bet. As
creyenders pointed out, a static var is a property of the class,
not the instance, so that tells you nothing, but I'm assuming that
you have other things going on which suggest it's the same
instance?</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/138600462012-02-21T13:09:14Z2012-02-21T13:36:42ZProblem Modular Context Being Cached by Main Application<div><p>Hehe I know that's a tough one. The lead Flash Developer of
another team where I work tried to look into it with me, but he
cannot find what's going on apart from the context being the same
name and being probably cached some where by RL or Flash
itself.</p>
<p>As I said, the communication between the module and the main swf
file can show me that the command catching the response from the
main swf file is called twice with 2 different current state, which
is not happening the first time I run the game :-)</p>
<p>So there's another small game instance living some where.</p>
<p>As I said as well, we have 12 other games, that are actually
Jigsaw games, that are exactly the same, but they have different
assets.<br>
We could see that as soon as you had run once, one of this 12
jigsaw game, no matter which one you were choosing the next time,
the first one you had run was always the one on screen, in term of
resources. We checked the URL to be sure we weren't loading the
same one again, and every thing was fine.</p>
<p>However, as soon as we changed the name of the context, so
instead of having 12 JigsawGameContext, we had JigsawGameContext_1,
JigsawGameContext_2, etc.. up to 12, then it was loading the
correct game each time.</p>
<p>I gotta say, those 12 jigsaw games don't hold any state, so I
cannot check if we have the same issue than with this other game in
terms of having more than one running.</p>
<p>Last interesting thing is when I run like 3/4 times the other
game, I can see the command getting the response from the server
called....3/4 times, so it's more like the swfs are staying some
where despite the fact that I unload them and dispose of them</p></div>Christophetag:robotlegs.tenderapp.com,2009-10-18:Comment/138600462012-02-21T13:58:43Z2012-02-21T13:58:43ZProblem Modular Context Being Cached by Main Application<div><p>As a diagnostic test, I would make it so that the second time
the game is loaded, it does not run the loading code. this will let
you find out what is holding the reference to the original loaded
version.</p>
<p>There's no reason why Robotlegs itself would be caching it - we
all use the modular Robotlegs regularly and don't generally see
this problem.</p>
<p>But I'd like to help you fix it - so if you want to zip up your
compiled application I can take a look with Monster Debugger?</p>
<p>I'm guessing in the end it'll either be one of the usual
suspects (an event listener not being removed, a static reference
accidentally kept to a deeply nested member etc) or it may even be
a problem with the Flash Loader itself (I've had to implement some
workarounds in my project because of Loaders corrupting
sometimes).</p>
<p>It can be solved though! Don't lose hope :)</p>
<p>Stray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/138600462012-02-21T14:36:49Z2012-02-21T14:36:50ZProblem Modular Context Being Cached by Main Application<div><p>Thanks Stray for the offer,</p>
<p>But it's a company project so I am not allowed to send you a zip
:-)</p>
<p>I have a class in that minigame containing only constants
though, do I have to manually do something on it to make sure it's
destroyed ?</p></div>Christophetag:robotlegs.tenderapp.com,2009-10-18:Comment/138600462012-02-21T15:41:45Z2012-02-21T15:41:46ZProblem Modular Context Being Cached by Main Application<div><p>I thought I was going to give you an update :-)</p>
<p>I have waited like 10/15 sec after the first launch/close and it
doesn't do it any more if I wait.<br>
So it could be just a matter of garbage collection happening late
?</p></div>Christophetag:robotlegs.tenderapp.com,2009-10-18:Comment/138600462012-02-21T15:50:01Z2012-02-21T15:50:01ZProblem Modular Context Being Cached by Main Application<div><p>Hi Christophe - that sounds like exactly what it is.</p>
<p>What's your app/player version?</p>
<p>You can force/hint gc in newer versions, but if that's not
viable then there are less elegant methods for forcing cleanup.</p>
<p>Stray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/138600462012-02-21T15:59:47Z2012-02-21T15:59:48ZProblem Modular Context Being Cached by Main Application<div><p>I force the gc when it's a game, and it fixes the issue.</p>
<p>People can only run our app if they have Flash 10, so I think
it's ok to force the gc, isn't it ?</p>
<p>Chris</p></div>Christophetag:robotlegs.tenderapp.com,2009-10-18:Comment/138600462012-02-21T16:13:58Z2012-02-21T16:13:58ZProblem Modular Context Being Cached by Main Application<div><p>That does sound fine - yes, I remember in FP9 it only worked for
debug players, but I think in FP10+ it's in the release player as
well.</p>
<p>Make sure you test with the release player as well though -
Adobe documentation on this is still a bit sketchy (as always).</p>
<p>Stray</p></div>Stray