Use a WeakMap instead of a Map to cache EnumWrapper instances. This ensures that EnumWrapper instances are garbage collected whenever their corresponding "enum-like" objects are garbage collected (no memory leaks), and should also improve cache lookup performance.
Because WeakMap solves the concern about memory leaks when ts-enum-util is used on temporary enum-like objects, there's really no need to opt out of caching any more. So the following API changes were made:
Removed EnumWrapper.createUncachedInstance()
Removed optional useCache param to the $enum() function (it now always uses the cache).
The $enum function was also slightly optimized by making it a direct reference to EnumWrapper.getCachedInstance.
Use a
WeakMap
instead of aMap
to cacheEnumWrapper
instances. This ensures thatEnumWrapper
instances are garbage collected whenever their corresponding "enum-like" objects are garbage collected (no memory leaks), and should also improve cache lookup performance.Because
WeakMap
solves the concern about memory leaks whents-enum-util
is used on temporary enum-like objects, there's really no need to opt out of caching any more. So the following API changes were made:EnumWrapper.createUncachedInstance()
useCache
param to the$enum()
function (it now always uses the cache).The
$enum
function was also slightly optimized by making it a direct reference toEnumWrapper.getCachedInstance
.