Solved

How to release SafeFileHandle in c#

Posted on 2010-08-25
1
1,371 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 16

Accepted Solution

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

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Suggested Solutions

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
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…

735 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