Solved

How to release SafeFileHandle in c#

Posted on 2010-08-25
1
1,318 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
Comment Utility
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now