Is there a way to return all unguarded objects?

I have a Linked Web data structure (?) That is. each object has a bunch of links to other objects.

So, I wrote a method that should "delete" the passed object, removing all references to it.

I need to test it and make sure that after the method is run, the specific object that I want to delete does not refer to anything else

How can i do this?

The idea would be to get the Garbage Collection to run my delete object method, and then get another GC to see if it found the object.

if he found an object for deletion, I would suggest that my method works but if he did not find anything to collect, I would assume that something is referencing it and he will have to connect this leak.

Is it possible? How?

Thanks Ryan

+3
source share
2 answers

You can track each object with WeakReferenceand check the property IsAliveafter garbage collection.

+4
source

It strikes me as an overly complicated way to verify your logic. I would build a couple of unit tests as follows.

  • Add an object to the Internet. In the test, keep a link to the object
  • Call the logic that disconnects the link from the network.
  • Go through (or cross) your website and use ObjectReferenceEquals to find out if this link is still hanging. Since you have many possible connections, this may not be the fastest operation. However, in a relatively small test this should be good.

, , . , , . .

+1

Source: https://habr.com/ru/post/1793496/


All Articles