jquery - How to clean memory of browser in javascript from objects and classes? -


i making quest game 3 scenes. player can move scene scene , go back. (like known classic quests: neverhood,machinarium,the curse of monkey island) each scene have it's own objects, classes , bags of graphic elements. here how scripts 1 scene.

<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>     <script type="text/javascript" src="js/jquery.gamequery-0.5.0.2.js"></script>  <!-- ////////////////////////////////////////////////     ///////////                 charecters            ////////////////////      /////////////////////////////////////////////////////////////// -->      <script type="text/javascript" src="js/charecters/player.js" id="player_anime"></script>     <script type="text/javascript"  src="js/charecters/mama.js" ></script>       <!-- ////////////////////////////////////////////////   ///////////                 scene globals            ////////////////////    /////////////////////////////////////////////////////////////// -->     <script type="text/javascript" src="js/scene_globals/scene2/audio.js"></script>     <script type="text/javascript" src="js/scene_globals/scene2/background.js" ></script>     <script type="text/javascript" src="js/scene_globals/scene2/scene.js"></script>      <!-- ////////////////////////////////////////////////    ///////////                 game controls            ////////////////////     /////////////////////////////////////////////////////////////// -->       <script type="text/javascript" src="js/game_control.js"></script> 

i want load scripts each scene asynchronously in order solve problem of memory usage. realized if destroy scripts , load others next scene, objects , graphic elements still stay in memory.

here general algorithm:

1) loading graphic , scripts first scene. 2) user pass first scene 3) erase objects, scripts , graphic of first scene 4) loading needs second scene

there way make it: instead of asyncronious solution, can put stuff each scene iframe. when iframe reloads next scene objects , graphic erase. here problem- how use objects , graphic in iframe parent page. (there interaction have)

i hope bad english enough make question clear.

waiting eny suggestions.

i aim adopt strategy :

  • adopt module pattern
  • write static, generic module, suitable scenes
  • for each scene, write javascript file containing appropriately constructed module containing data/functions specific scene.
  • include in generalized framework means load (using eg. jsonp) appropriate module required scene.

with module pattern, make sure module doesn't "overwrite" module of same name. however, that's want in case.

on loading new module, garbage collection after deletion of "overwritten" module.

as javascript's garbage collection lazy, force delete command prior loading new scene. provision need make ensure modules defined properties of outer project namespace (as typical module pattern).

correctly implemented, place one member in global namespace (plus 1 or more each utility/library object such jquery).


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -