C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Memory management in C# .NET using SetProcessWorkingSetSize API


Posted Date: 14 Feb 2007    Resource Type: Articles    Category: .NET Framework

Posted By: Chandrashekar R_S       Member Level: Bronze
Rating:     Points: 10



The status of this resource is Pending. The webmaster may be reviewing this resource or have put on hold.



//add these name space
using System.Collections;
using System.Runtime.InteropServices;



class Memory
{
[DllImport("kernel32.dll")]
public static extern bool SetProcessWorkingSetSize( IntPtr proc, int min, int max );
public void ReduceMemory()
{
GC.Collect() ;
GC.WaitForPendingFinalizers() ;
if(Environment.OSVersion.Platform == PlatformID.Win32NT)
{
SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1) ;
}
public void Memory()
{
ReduceMemory() ;
}
}


Call ReduceMemory() method in form load or in constructor of the class



We can temporarily trim the working set of the specified process to zero by setting -1 for both dwMinimumWorkingSetSize and dwMaximumWorkingSetSize. But gradually application starts acquiring memory, so in the long run we can call SetProcessWorkingSetSize function for every 30 seconds using timer. This will make sure that our application use less memory.







Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Evaluating String Expression - VB.Net
Previous Resource: Problem with w3wp.exe, the Asp.net worker process in Windows 2003
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

conference call definitions

Contact Us    Privacy Policy    Terms Of Use