Solved

How to release SafeFileHandle in c#

Posted on 2010-08-25
1
1,354 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

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