Who is referencing this object?

Hi all,
Before disposing an object I'd like to know if there are other objects referencing it, because otherwise it will not be destroyed by garbage collector.

Any idea
Thanks in advace

Andrea



Answer this question

Who is referencing this object?

  • The MATRIX

    There is no way to know if an object is being referenced.

    Why would you want to know if the objects being referenced by others in order to call dispose If you implement the IDisposable pattern its the responsiablity of the caller of your object to manually call Dispose on your object to free any resources held.

    Regards,
    Saurabh Nandu


  • Mike Vargas

    I have one to many situation, where my object is referenced by different types with several instances. Some of those types uses a field or a collection to reference the object.

    I do use IDisposable , however each type using my object have to release my object before I complete the Dispose otherwise the object will remain attached and not begin disposed.

    Also each type referencing my object has different use for the object, so as I remove the object I need to update those types.

    At the moment I have 2 solutions for this problem:
    1) cross referencing my object with who is using it. Which is typically used in those situation however I don't like to take care of related implications.
    2) Implement an OnDisposing event for my Object, to be called during the Dispose. Which is what I use at the moment.

    If .Net would provide a collection of object using my object, I would implement a simple method for each type called by my object during the Dispose.

    Andrea 


  • Jack gillespie

  • PeterVrenken

    Thank you


  • Who is referencing this object?