Linked Questions
47 questions linked to/from Do event handlers stop garbage collection from occurring?
1 vote
2 answers
703 views
How to dispose the local variable that contains event [duplicate]
Possible Duplicate: Do event handlers stop garbage collection from occuring? I had one wp7 application like this: private void button1_Click(object sender, RoutedEventArgs e) { ...
0 votes
1 answer
295 views
Is it neccessary to unsubscribe eventhandler of an owned object? [duplicate]
It's important to mention that the question is about an owned object which its lifecycle will be controlled by the container it is declared in. For an external object which has been assigned from ...
2 votes
0 answers
240 views
C# Filewatcher on a config file [duplicate]
What I'm wanting to do is create a file watcher that is monitoring for any changes in my services config file. When it detects any changes, the service should restart automatically so the changes can ...
1 vote
0 answers
66 views
Will this code cause a memory leak? [duplicate]
I have a social network, where I can place comments on posts. I havce implemented this using a ReactionController that handles API calls for a post that has an event that indicates that the API call ...
0 votes
0 answers
49 views
Can an event handler test if its object is eligible for garbage collection [duplicate]
Unless I've fundamentally misunderstood the way events and garbage collection work in C#, if an object has subscribed to an event, the event can still be raised on that object, and the event handler ...
1 vote
0 answers
37 views
Does registring to events saves a class from bieng garbage collected? [duplicate]
If the only thing that ClassA does is to subscribe to events from ClassB -which is a long living class- like this static void Main() { new A(B); } class ClassA { public ClassA(ClassB b) { ...
55 votes
8 answers
171k views
Notify ObservableCollection when Item changes
I found on this link ObservableCollection not noticing when Item in it changes (even with INotifyPropertyChanged) some techniques to notify a Observablecollection that an item has changed. the ...
52 votes
6 answers
56k views
FileSystemWatcher not firing events
For some reason, my FileSystemWatcher is not firing any events whatsoever. I want to know any time a new file is created, deleted or renamed in my directory. _myFolderPath is being set correctly, I ...
45 votes
6 answers
23k views
When should I implement IDisposable? [duplicate]
What is the best practice for when to implement IDisposable? Is the best rule of thumb to implement it if you have one managed object in the class, or does it depend if the object was created in the ...
34 votes
4 answers
24k views
WeakReference and event handling
Is it a good practice to implement event handling through WeakReference if that event is the only thing holding the reference and that we would need the object to be garbage collected? As an ...
8 votes
5 answers
10k views
c# memory allocation and deallocation patterns
Since C# uses Garbage Collection. When is it necessary to use .Dispose to free the memory? I realize there are a few situations so I'll try to list the ones I can think of. If I close a Form that ...
6 votes
5 answers
2k views
Will .Net Garbage Collect an object that's not referenced, but has a thread that's doing work?
I have the following code (cut down for readability): Main Class: public StartProcess() { Thinker th = new Thinker(); th.DoneThinking += new Thinker.ProcessingFinished(ThinkerFinished); ...
9 votes
6 answers
5k views
Is it good practice to unregister from external events in the Dispose method of an IDiposable class?
I read the excellent answer explaining how to use the Dispose pattern, and also why it works that way. Proper use of the IDisposable interface The post clearly states that you would want to use the ...
3 votes
4 answers
176 views
Should I change my object to Null after removed from my List?
I have a class which has a static List<T> field inside which I hold all my objects; each object represents a process that is running and its properties. After the process finishes its job, the ...
11 votes
1 answer
2k views
Do I need to keep a reference to a FileSystemWatcher?
I'm using a FileSystemWatcher (in an ASP.NET web app) to monitor a file for changes. The watcher is set up in the constructor of a Singleton class, e.g: private SingletonConstructor() { var ...