tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/862-unmap-a-singleton-in-robotlegs-152Robotlegs: Discussion 2018-10-18T16:35:38Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/148680572012-03-29T22:21:32Z2012-03-29T22:21:32Zunmap a singleton in robotlegs 1.5.2<div><p>Hello!</p>
<p><code>unmap()</code> simply removes the mapping. It will not
null out any existing references to injected instances. If you
create a new mapping, a new instance will be used for future
injections.</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/148680572012-03-30T05:06:43Z2012-03-30T05:07:37Zunmap a singleton in robotlegs 1.5.2<div><p>hi,</p>
<p>i have a simple scenario. i have some services (singletons) for
my game lobby. when the game starts i want to remove these
singleton services to free up memory. but on returning back from
the game to the lobby i want a new instance of this service to be
created. so i was hoping on gamestart i will do injector.unmap() so
that the service singleton gets removed. i understand that if i am
holding a reference to that singleton elsewhere it will not be
removed. but i can make sure of that. just want to know how to make
sure that robotlegs loses a reference to that singleton so that it
may free up space.</p></div>itsmylifesohamtag:robotlegs.tenderapp.com,2009-10-18:Comment/148680572012-03-30T15:20:16Z2012-03-30T15:20:16Zunmap a singleton in robotlegs 1.5.2<div><p>In that case, you are correct. Calling unmap will release the
cached singleton instance. As long as you've cleaned up all you're
own references, the singleton instance should be free for garbage
collection. Later, when you recreate the mapping, a new instance
will be created and cached for future injections. Hope that
helps!</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/148680572012-03-30T18:18:13Z2012-03-30T18:18:13Zunmap a singleton in robotlegs 1.5.2<div><p>yea that clears it.<br>
so just so i understand correctly ..should i be calling
injector.map() immediately after calling unmap() ?<br>
i hope that the new instance created and cached for future
injections will not be active or eat memory until it is injected
after coming back from lobby? am i right?</p></div>itsmylifesohamtag:robotlegs.tenderapp.com,2009-10-18:Comment/148680572012-03-30T18:23:42Z2012-03-30T18:23:42Zunmap a singleton in robotlegs 1.5.2<div><p>Yep, mappings do not eagerly create instances, so the new
instance will only be created on the next injection.</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/148680572012-03-31T10:07:27Z2012-03-31T10:07:27Zunmap a singleton in robotlegs 1.5.2<div><p>thanks a lot! :)</p></div>itsmylifesoham