Reputation: 109
i have a Model
and class - Factory
which creates, load and save this model.
I want completely release all references to this Model
save and dispose, but i don't know how can i tell all classes who keep references to Model
release it.
I only see 2 solutions:
Factory
WeakReference to Model
and keep strong reference only in Factory
but i have no guarantee that Model
will be destroyed right after releasing last strong reference.Model
or to classes who owns Model
to release reference.Upvotes: 0
Views: 32
Reputation: 77295
If it's not technically about lifetime of the memory used, you could have a flag in the model, that you set once it's supposed to be destroyed. All operations of the model would check this flag and throw an exception if it's set, so it's unusable afterwards.
Some classes do this in their Disposable implementation, where you get an AlreadyDisposedException when you call methods after disposing it.
Upvotes: 1