Let's say I create an object, and that object starts a thread, and gives one of its private instance methods to ThreadStart
. Later, all references to that object are gone. What happens? Is the object is never garbage collected because the thread holds a reference to it through the this
pointer? On the other hand, if I use a static method, how can the thread detect that its object was garbage collected and end?
I know I shouldn't normally make threads lifetime dependent on garbage collection. I don't want my object to leak when it's not disposed correctly.