Bug 17601 - Code issue for static event handlers
Summary: Code issue for static event handlers
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: C# Binding ()
Version: unspecified
Hardware: PC Mac OS
: Normal normal
Target Milestone: 4.2.4 (from master)
Assignee: Mike Krüger
Depends on:
Reported: 2014-02-04 18:17 UTC by Marius Ungureanu
Modified: 2014-03-13 10:01 UTC (History)
3 users (show)

Is this bug a regression?: ---
Last known good build:

TestProject (5.85 KB, application/octet-stream)
2014-02-19 11:02 UTC, Sadik Ali
Test Project (12.09 KB, application/x-zip-compressed)
2014-03-13 09:33 UTC, Tajinder Singh

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Marius Ungureanu 2014-02-04 18:17:56 UTC
If we register to a static eventhandler but not unregister from it, it causes a memory leak.
Comment 1 Mike Krüger 2014-02-05 05:59:21 UTC
I implemented a code issue for that.

Would be nice if you could check that for your use cases.
Comment 2 Sadik Ali 2014-02-19 11:02:32 UTC
Created attachment 6088 [details]

To checked this issue, I have created a static event handler. Attached sample project is for that same. I followed below steps:

1. Created Event class for static event handler.
2. Created two methods in same class.
3. Created two object (Object2, Object3) of Event class in main class.
4. Register Event handler with these object.
5. Unregister Object3 and invoked event handler.
6. Noticed that Event handler invoked both methods.

Please let me know if this test project is sufficient to verify this issue.
Comment 3 Mike Krüger 2014-02-19 11:06:55 UTC
Ah you try to add to a static event in a static method - that is a case where I can't really decide if it's a problem or not.
Comment 4 Tajinder Singh 2014-03-13 09:33:37 UTC
Created attachment 6301 [details]
Test Project
Comment 5 Shruti 2014-03-13 10:01:54 UTC
I have created sample project for Static Event Handler added in Comment 4. 

1. I have added code to release the object.
2. I go to task manager to check it, memory was not leaking.
3. Then i commented the code which release the object.
4. Again go to task manager to check the memory.
5. I followed the step 3 and 4 more than 5-6 times.

Memory was not leaking.

Environment Info :
XS 4.2.4 (build 32)

As per my understanding, it seems to be working fine. Please review and let me know if you have any suggestion for the same.