How to limit the memory usage of a VB.NET process in Win Server 2008

Posted on 2010-01-03
Last Modified: 2012-06-27
Hi there. I currently host a website with a VPS (Virtual Private Server) which only has 1GB RAM. This limited memory is generally ok, however I need to run an console application (written in VB.NET) which can run at quite a high memory usage.

I don't need the console application to run fast... just to run all the way through without dying prematurely, having reached the machine's RAM limit.

As the server is a VPS I don't think I can make use of hard drive space to substitute for RAM (page file).

Instead, I'm hoping there is a way to limit the amout of RAM that the process uses, either through a Windows Server 2008 setting or somehow through the VB.NET code that the console application is written in.

Any advice greatly appreciated.
Question by:lawso
    LVL 11

    Expert Comment

    The Memory usage displayed in Task Manager is not correct for applications...  Your usage is probably very low, the displayed amount is the Working Set which includes shared memory... If other applications request memory then .net will give it back.

    Here is an article on it:

    Basically there is not much you can do about it...  If you create applications in native C++ then you can use the memory tab in task manager to monitor the memory usage...

    Author Comment

    The problem is that it is running on VPS Container that shutsdown Services when the memory spike above the amount allocated to the VPS, even if the amount is not correct.
    LVL 11

    Accepted Solution

    Make sure you are releasing all objects correctly and disposing objects you call if they are available...  Try to reuse any objects in there you can instead of declaring now objects...

    Look into running it as a scheduled task instead of a console app... That way it opens, runs what it needs and closes can set it to do that say every 30 min.... Also you may want to look at if you can run it remotely, perhaps transmit the data via a web service....

    Hope this gives you some idea's
    LVL 11

    Expert Comment

    I said declaring now objects... meant to say declaring new objects...
    LVL 10

    Expert Comment

    As ICaldwell mentioned, there really isn't much an application can do to influence it's memory usage. In Windows physical memory is completely managed by the system, not the application. Task Manager does not show this but RAM will be used to the fullest possible extent, no matter how much or little might be running. Free memory is a great evil in a modern OS. Memory is dynamically assigned to running processes according to their needs and RAM availability. Like RAM, the pagefile is managed by the system and cannot be used directly by applications. What Task Manager shows as "Available" memory DOES NOT impose a limit on what applications may still be run, only on how well they will perform. Your console app should run, even if available memory is low. If necessary, the system will take memory from other processes to meet it's needs. This is a routine and completely normal situation.

    Author Closing Comment

    Thanks ICaldwell and others that commented

    Featured Post

    Want to promote your upcoming event?

    Is your company attending an event or exhibiting at a trade show soon? Are you speaking at a conference? Spread the word by using a promotional banner in your email signature. This will ensure your organization’s most important contacts are in the know.

    Join & Write a Comment

    I had a question today where the user wanted to know how to delete an SSL Certificate, so I thought that I would quickly add this How to! Article for your reference. WHY WOULD YOU WANT TO DELETE A CERTIFICATE? 1. If an incorrect certificate was …
    You might have come across a situation when you have Exchange 2013 server in two different sites (Production and DR). After adding the Database copy in ECP console it displays Database copy status unknown for the DR exchange server. Issue is strange…
    This tutorial will show how to push an installation of Backup Exec to an additional server in both 2012 and 2014 versions of the software. Click on the Backup Exec button in the upper left corner. From here, select Installation and Licensing, then I…
    This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…

    746 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

    16 Experts available now in Live!

    Get 1:1 Help Now