weak_collections 1.2.0+1 copy "weak_collections: ^1.2.0+1" to clipboard
weak_collections: ^1.2.0+1 copied to clipboard

Collection of soft references. Weak reference effect achieved through WeakReference and Finalizer.

weak_collections #

This package contains the classes:

  • WeakHashMap
  • WeakHashSet

WeakHashMap #

A WeakMap allows you to garbage collect its keys, and remove references to values after keys are recycled. This means that when the key is recycled, the value will also be recycled.

Object? o = Object();
Object o2 = Object();
WeakHashMap weakMap = WeakHashMap();
weakMap[o] =o2;
o = null;

// After garbage collection weakMap[o] will be removed.
print(weakMap.length); // print 0  

WeakHashSet #

WeakSet will automatically free objects stored in unreferenced. This means that if an object has no other application, it will not exist in the WeakSet.

Object? o = Object();
WeakHashSet weakSet = WeakHashSet();
weakSet.add(o);
o = null;

// After garbage collection [o] will be removed.
print(weakSet.length); // print 0  

Usage #

See example for detailed test case.

Issues #

If you encounter issues, here are some tips for debug, if nothing helps report to issue tracker on GitHub:

2
likes
150
pub points
31%
popularity

Publisher

verified publisheraymtools.com

Collection of soft references. Weak reference effect achieved through WeakReference and Finalizer.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

More

Packages that depend on weak_collections