weak_collections 1.2.1 copy "weak_collections: ^1.2.1" to clipboard
weak_collections: ^1.2.1 copied to clipboard

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

example/example.dart

import 'package:weak_collections/weak_collections.dart';

void main() {
  Object? o = Object();
  Object o2 = Object();
  WeakHashMap weakMap = WeakHashMap();
  WeakHashSet weakSet = WeakHashSet();
  weakMap[o] = o2;
  weakSet.add(o);
  o = null;
  List lis = [];
  Future(() => '').then((_) {
    lis = List.filled(1020000, () => Object());
    print(weakMap.length);
    Future(() => '').then((_) {
      lis = List.filled(1020000, () => Object());
      print(weakMap.length);
      Future(() => '').then((_) {
        lis = List.filled(1020000, () => Object());
        print(weakMap.length);
        Future(() => '').then((_) {
          for (int i = 0; i < 100; i++) {
            lis = List.filled(1020000, () => Object());
          }
          print(weakMap.length);
          Future(() => '').then((_) {
            lis = List.filled(1020000, () => Object());
            print(weakMap.length);
            Future(() => '').then((_) {
              lis = List.filled(1020000, () => Object());
              print(weakMap.length);
              Future(() => '').then((_) {
                lis = List.filled(1020000, () => Object());
                print(weakMap.length);
                Future(() => '').then((_) {
                  lis = List.filled(1020000, () => Object());
                  print(weakMap.length);
                  Future(() => '').then((_) {
                    lis = List.filled(1020000, () => Object());
                    print(weakMap.length);
                    Future(() => '').then((_) {
                      lis = List.filled(1020000, () => Object());
                      print(weakMap.length);
                    });
                  });
                });
              });
            });
          });
        });
      });
    });
  });
  lis.length;
}
2
likes
150
points
233
downloads

Publisher

verified publisheraymtools.com

Weekly Downloads

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