I have objects subscribing to a custom event so I can change them all them at once. Trouble is, that that will never let them go out of scope and be garbage-collected. Even nulling Controls will not null the Controls contained in them. In fact, even the nulled controls will not be collected! (Please do correct me if I’m wrong on any point.)
So I thought of a solution which would be to wrap the event in a class, create an instance of that class and use it, and then null it when I want to let the objects get GC’d, and create a new instance of it to continue.
However, I have two questions about it:
- Will it actually work, or will the objects still evade being GC’d?
- Is there any simpler, more straightforward way to achieve this?
EDIT: part 2 has been answered (in a comment to an answer). Simply do: event_name = null;. I’m still wondering, though, about part 1 – would it work?
The answer to part 2 (by Servy’s comments):