Undisposed instances of BinaryReader in localized forms

R

Robert Misiak

I've been trying out the .NET Memory Profiler
(http://www.scitech.se/memprofiler/) and I found an excessive number of
undisposed instances of BinaryReader after opening and then closing various
forms. The thing that these forms have in common is that they are localized
for both English and Dutch. I tried adding resources.ReleaseAllResources()
from the destructor but that had no effect. I'm pretty sure that it is the
localization code but of course I'm not totally sure, does anyone have any
more information about this, or perhaps what I can do to dispose all of the
BinaryReader instances? This application is designed to run 24/7 from the
system tray so its important to me to patch up any memory leaks.

Thanks,
Robert
 
?

=?ISO-8859-2?Q?Marcin_Grz=EAbski?=

Hi Robert

You should not leave any release/free work to destructors!

The best way to keep resources free is to Close (eventually Dispose)
every Reader/Stream after its job is done.
If there are more instances of BinaryReader then you should keep
references of unclosed ones (in Array or List) till they will be
Closed.

Regards

Marcin

PS: You should close reader/stream in "finally" block.in case of
exception
 
R

Robert Misiak

Hi Marcin-

Perhaps I should have clarified that BinaryReader isn't directly called
anywhere in my code - I'm assuming that the Windows
Form Designer localization code (from ResourceManager) is calling it.

Robert
 
?

=?ISO-8859-2?Q?Marcin_Grz=EAbski?=

Hi Robert,

It looks like another .NET internal problem.

"ReleaseAllResources()" should work... but you'll never know.

hmmm... I can only recommend to get resources from out of
"InitializeComponent()" in contructor ( TODO block ).
Then release them by "ReleaseAllResources()" at the end of
constructor.

If you are initializing more forms/controls/components then don't
forget to dispose them one by one at "the end".

Marcin

PS: Do you have memory-taking resources? Text & icons or
more?
 
R

Robert Misiak

Hi Marcin-

Yes, I've tried using ReleaseAllResources at the end of
InitializeComponent - but it didn't solve the BinaryReader problem. There
are quite a few memory-taking resources in the program, but I've taken a lot
of care to ensure that they're Disposed after they've been used.

Robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top