iHDSim crash referencing unloaded element

This is both a question and a comment/bug report. Steps to reproduce the bug (iHDSim released 8/29):
  1. Load iHD application. In script, after markup is loaded, store a reference to an element on the current page (I used getElementById()).
  2. Use the <link> tag in a <cue> to cause a new markup page to replace the current page.
  3. Attempt to reference a property of the element stored in (1). The reference attempt is surrounded by try...catch().
  4. iHDSim crashes with a memory reference error.
Questions:
  1. What is the correct behavior I'm guessing an exception should be thrown.
  2. Is there a way to check whether an element exists before trying to reference it's property to trigger an exception It seems that something is getting deleted/garbage collected, while a reference to it still remains.
  3. Is it legal to even retain a reference to an element in code while using a link Should some kind of garbage collector automatically set any references to elements within a page to NULL in order to be able to unload the prior page without creating bad memory references This probably leads to an abstract discussion of garbage collectors in general, but I'm just curious...
Sorry, this became several questions...


Answer this question

iHDSim crash referencing unloaded element

  • Youngd

    Actually I was depending on the exception to handle the special (infrequent) case that a new markup file had been loaded, and re-get the zombified element. My goal was to avoid writing special handling into the onMarkupLoaded() callback. Nothing wrong with that, is there

  • Mindy Kelly

    Nothing wrong with that per se, except that from a practical point of view it won't work in iHDSim until that bug is fixed... :-(

    So whilst in general the strategy is fine, in this case you will need to use a markupLoadedHandler to re-set all your cached info. Probably a good practice to get into anyway.



  • Alainna

    The element you have a reference to should just become a "zombie" that throws exceptions on all operations. Clearly that is not happening though :-)

    Basically you should avoid this behaviour, since it won't work in any players. Of course iHDSim shouldn't crash, but even when the bug is fixed your code won't do anything useful (just throw), so maybe the crash is a helpful indication that you're doing something wrong :-) ).



  • iHDSim crash referencing unloaded element