?
Solved

How to release SafeFileHandle in c#

Posted on 2010-08-25
1
Medium Priority
?
1,475 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 2000 total points
ID: 33527523
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses
Course of the Month15 days, 6 hours left to enroll

840 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