Solved

How to release SafeFileHandle in c#

Posted on 2010-08-25
1
1,362 Views
Last Modified: 2013-11-27
i am using a pipe schema to communicate with different applications.  The problem is that there are memory leaks and i think it is due to unmanaged code from calling kernel32.dll.  Every time I connect a new client to the server there memory jumps way up and when I exit that read thread then it is still not released.  Heres the release part of my code:
(Client class has 2 properties: SafeFileHandle & FileStream)

            client.stream.Close();
            client.handle.Close();
            lock (this.clients)
                this.clients.Remove(client);
            //Marshal.ReleaseComObject(client.handle); throws an EXCEPTION
            client.handle.SetHandleAsInvalid();
            GC.Collect();
0
Comment
Question by:htn5ca
1 Comment
 
LVL 16

Accepted Solution

by:
Vikram Singh Saini earned 500 total points
ID: 33527523
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question