0

I am working on a simple api that creates and manages the creation of some html ( doesn't matter really.. ).

Anyway, this api is wrapped in one of the UMD snippets, which basically receives an anonymous function as one of its arguments:

Take a look at the code for the actual question:

What happens to 'queues' in terms of memory when:

  1. The initial state turns to "after usage" state?
  2. If "someUniqueKey1" object is referenced by some anonymous function passed to jQuery ?

Code:

+function( root, factory ) {
  if ( typeof define === 'function' && define.amd ) {
    // AMD. Register as an anonymous module.
    define( [ 'jquery' ], factory );
  } else if ( typeof exports === 'object' ) {
    // Node. Does not work with strict CommonJS, but
    // only CommonJS-like environments that support module.exports,
    // like Node.
    module.exports = factory( require( 'jquery' ) );
  } else {
    // Browser globals (root is window)
    root.Alert = factory( jQuery );
  }
}( this, function( $ ) {
    var queues = {}; // <-- initial state

    // after usage state:
    queues = {
      "someUniqueKey1": { "someProperty": [] },
      "someUniqueKey2": { "someProperty": [] },
    }

    // constructor some here...

    // prototyping goes here..

    // ....

    return alertAPI
  }
);

I tried profiling using chrome dev tools, but all I can see is the created instances and what happens when they are removed.

elad.chen
  • 2,375
  • 5
  • 25
  • 37

1 Answers1

1

If there is no reference associated with any variable/object then it is marked by the browser for garbage collection . You can learn more about it here What is JavaScript garbage collection?

Community
  • 1
  • 1
Kushal
  • 1,360
  • 6
  • 16