I have been working on the codes to safely and efficiently dispose unmanaged objects in C#. This is a Bitmap object created with an image. I like to track the handle to find out the status of image in memory before and after calling Dispose(). Is there a good way to figure out if a handle still pointing a valid object after Dispose() gets called?
Asked
Active
Viewed 57 times
0
-
So its an unmanaged object handle? do you want to track it through code? – Yacoub Massad Oct 15 '15 at 16:20
-
No, do not use an oracle. It is your code that calls Dispose() so you basically cannot not know that it was disposed. Use a *bool* variable to keep track. – Hans Passant Oct 15 '15 at 18:48
1 Answers
0
You can use Process Explorer to track the objects used by your process. If your process closes the handle correctly, then you can see through process explorer that the process no longer holds a handle to the object.

Yacoub Massad
- 27,509
- 2
- 36
- 62
-
Thanks. Sounds good. Is this a third part framework. Unfortunately, the company computer won't allow any non-approved or non-authorized installation... Is there any built-in functions? – Eric Oct 15 '15 at 16:31
-
This tool is from Microsoft. I am not sure if there is a built-in function to do this. I think under the hood, Process Explorer installs a driver that allows it to do things that cannot be done in user mode. – Yacoub Massad Oct 15 '15 at 16:37
-
Process Explorer inspects kernel HANDLEs.... completely unrelated to the question. – Ben Voigt Oct 15 '15 at 18:37
-
@BenVoigt Well, yes and no. You are right that it does not display GDI objects in the handles view. However, you can still see the number of GDI objects per process by adding the GDI Objects column to the main view. – Yacoub Massad Oct 15 '15 at 18:48
-
1@Eric, [this link](http://stackoverflow.com/questions/251343/how-to-get-gdi-objects-associated-to-a-process) seems to be a similar question to yours – Yacoub Massad Oct 15 '15 at 18:48