gbtb16/kiwi

Registered objects life cycle.

Closed this issue · 2 comments

What is the registered object life cycle? If on a screen I retrieve an object what happens when I go out of this screen?

Reading the code, i saw the object has been created only when I retrieve it. So what is the moment it is destroyed and go out of memory, or the objects stay on memory all the time app's live?

That is not clear to me, anyone can helpme?

Thanks

Hi @LucasFaiska I have read the code, it is stayed in the memory.if you unregistered the instance, next time it will throw error that instance is not register.
resolve method

 T resolve<T>([String name]) {
    Map<Type, _Provider<Object>> providers = _namedProviders[name];

    assert(silent || (providers?.containsKey(T) ?? false),
        _assertRegisterMessage<T>('not', name));
    if (providers == null) {
      return null;
    }

    return providers[T]?.get(this);
  }

unregister method

void unregister<T>([String name]) {
    assert(silent || (_namedProviders[name]?.containsKey(T) ?? false),
        _assertRegisterMessage<T>('not', name));
    _namedProviders[name]?.remove(T);
  }

so it should resolve the instance next time after we unregistered them.

Because all the dependencies are kept in a Map you have to handle the life cycle yourself.
By default: once registered it will always be available.

If you want to remove an object from the KiwiContainer you have to manually unregister when you want to remove the object.

If you have any more questions, feel free to comment or reopen this ticket