Caplin Trader 4.0.3

Class: module:br/util/MapFactory



Utility class that prevents memory leaks in IE when using long running maps that are added to and removed from over time.

Using this class has a penalty in performance and code beauty. Only use this when you are keeping a map for a long time and will be removing items and adding items with new names (not previously used) repeatedly.

Users of this class should not perform any browser detection themselves, as this is handled internally, and normal maps are returned for browsers that do not leak memory.


new module:br/util/MapFactory()

This is a utility and does not need to be constructed.


(inner, readonly) REMOVAL_LIMIT :int

A constant that defines the number of removals (as performed with .removeItem) before the map is replaced with a new one.
  • int


(static) createMap()

Creates a map that doesn't leak when used in conjunction with .removeItem.
A specially modified map object that allows the MapFactory to determine when any clean-up should occur, or a normal map object for browsers that do not leak.

(static) removeItem(mapToRemoveFrom, keyToRemove) → {Object}

Removes an item from the map.

If cleanup occurs, then the map will be replaced with a completely new one, and so any references to the map must be reset whenever this method is called, for example: this.m_mMap = MapFactory.removeItem(this.m_mMap, sItemKey);

Name Type Description
mapToRemoveFrom Object The map the item will be removed from.
keyToRemove String The key of the item to be removed from the map.
A reference to the updated map — typically this will just be mapToRemoveFrom, but may be a new map reference if the map has been replaced with a new instance.