473,246 Members | 1,382 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,246 software developers and data experts.

Forcefully Releasing memory

Hi all

I am having application in c# where i am loading one table of database
into dataset.
My table is of large size. so whenever i am loading that into dataset
my memory size is getting increased.

So what i want is as soon as i am setting dataset to null, memory
should be released.
But when i am looking into task manager for memory useage what i am
getting is same memory is till occupied by my application.

Can some one tell me how to forcefully release memory.

Please help me as this is very important for me.
Thanks in advance.

Nov 18 '05 #1
7 25883
Call GC.Collect().

That forces the garbage collector to collect the memory.

Pete
<tr**************@yahoo.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
Hi all

I am having application in c# where i am loading one table of database
into dataset.
My table is of large size. so whenever i am loading that into dataset
my memory size is getting increased.

So what i want is as soon as i am setting dataset to null, memory
should be released.
But when i am looking into task manager for memory useage what i am
getting is same memory is till occupied by my application.

Can some one tell me how to forcefully release memory.

Please help me as this is very important for me.
Thanks in advance.

Nov 18 '05 #2
Hi

I tried with calling Gc.collect. But still memory usage in task manager
remains same.

I don't know why this is happening.

If you know reason behind this, please tell me.

thanks.

Nov 18 '05 #3
Pete Davis wrote:
Call GC.Collect().
That forces the garbage collector to collect the memory.
Well, calling GC.Collect just asks GC to "please collect as soon as possible" which can be minutes...

Unfortunately all this dancing around GC doesn't help in many cases. We had a weird problem with
dramatically increasing memory thought we were releasing all datasets and arrays and profiler was
saying it's ok, so we finally came up with a solution:
Calling this function will "shake" your avail memory which does really help - you going to see an
immidiate used memory drop.

bool bTipAction = true;

public static void SetWorkingSet()
{
//Needs Admin rights on the machine

try
{
System.Diagnostics.Process loProcess = System.Diagnostics.Process.GetCurrentProcess();
if(m_bTipAction == true)
{
loProcess.MaxWorkingSet = (IntPtr)((int)loProcess.MaxWorkingSet - 1);
loProcess.MinWorkingSet = (IntPtr)((int)loProcess.MinWorkingSet - 1);
}
else
{
loProcess.MaxWorkingSet = (IntPtr)((int)loProcess.MaxWorkingSet + 1);
loProcess.MinWorkingSet = (IntPtr)((int)loProcess.MinWorkingSet + 1);
}
m_bTipAction = !m_bTipAction;
}
catch(System.Exception)
{
}
}
Good luck,
Andrey

Pete
<tr**************@yahoo.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
Hi all

I am having application in c# where i am loading one table of database
into dataset.
My table is of large size. so whenever i am loading that into dataset
my memory size is getting increased.

So what i want is as soon as i am setting dataset to null, memory
should be released.
But when i am looking into task manager for memory useage what i am
getting is same memory is till occupied by my application.

Can some one tell me how to forcefully release memory.

Please help me as this is very important for me.
Thanks in advance.

Nov 18 '05 #4
Here's some Remarks from MSDN:

Use this method to attempt to reclaim all memory that is inaccessible.
However, the Collect method does not guarantee that all inaccessible memory
is reclaimed.

All objects, regardless of how long they have been in memory, are considered
for collection; however, objects that are referenced in managed code are not
collected. Use this method to force the system to attempt to reclaim the
maximum amount of available memory.

Somewhat Ambiguous....
<tr**************@yahoo.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
Hi

I tried with calling Gc.collect. But still memory usage in task manager
remains same.

I don't know why this is happening.

If you know reason behind this, please tell me.

thanks.

Nov 18 '05 #5
hi

thanks for your reply.

but i am not getting this function.

It is like instead of calling co.collect, i have t call setworkingset
function.

if you can explain this little bit, then it will easier for me to use
it in my code.

thanks.

Nov 18 '05 #6
See inline

Willy.

"MuZZy" <le*******@yahoo.com> wrote in message
news:eb********************@comcast.com...
Pete Davis wrote:
Call GC.Collect().
That forces the garbage collector to collect the memory.
Well, calling GC.Collect just asks GC to "please collect as soon as
possible" which can be minutes...


NO, this is not true, calling GC.Collect is honoured as soon as the GC is
able to kick in, that is when managed code is at a GC safe point, I hope
your code doesn't spend minutes to reach a safe point :-).
Unfortunately all this dancing around GC doesn't help in many cases. We
had a weird problem with dramatically increasing memory thought we were
releasing all datasets and arrays and profiler was saying it's ok, so we
finally came up with a solution:
Calling this function will "shake" your avail memory which does really
help - you going to see an immidiate used memory drop.

This is not a solution, because there is no problem, "dramatic increase" of
memory means what in terms of free memory? Does your application or other
applications running in the system suffer from a lack of memory?
If the answer to this question is NO, well, don't call GC.Collect or don't
trim the Working Set of your application.
If the answer is yes, run a memory profiler and look at your memory
allocation patterns, take a close look at your containers like Datasets,
Arraylists etc..., they are so easy to use but he! they come at a price and
they are largely overused, the result is that .NET applications are known to
be memory hungry. Right, .NET makes it possible to build windows
applications real fast, but to build well designed and well performing (in
terms of performance and resource consumption) is just as hard as any other
development platfom, with one exception, the time you win during development
can now be spent for designing and testing etc....

bool bTipAction = true;

public static void SetWorkingSet()
{
//Needs Admin rights on the machine

try
{
System.Diagnostics.Process loProcess =
System.Diagnostics.Process.GetCurrentProcess();
if(m_bTipAction == true)
{
loProcess.MaxWorkingSet = (IntPtr)((int)loProcess.MaxWorkingSet - 1);
loProcess.MinWorkingSet = (IntPtr)((int)loProcess.MinWorkingSet - 1);
}
else
{
loProcess.MaxWorkingSet = (IntPtr)((int)loProcess.MaxWorkingSet + 1);
loProcess.MinWorkingSet = (IntPtr)((int)loProcess.MinWorkingSet + 1);
}
m_bTipAction = !m_bTipAction;
}
catch(System.Exception)
{
}
}

What you are doing is realy bad, just like calling GC.Collect without having
any serious reason, reducing the working set is just as bad (well actually
worse). Don't fool yourself in thinking that your application uses less
memory because you reduced the WS, all you did is throw away (valuable?)
pages from memory (to the paging file). The result is that you disturb the
OS memory manager and pager, also you are inducing a lot of hard page faults
whenever a paged file has to be brought back into the working set. Worse you
disturb the GC even more when doing this, think what happens if pages from
the managed heap are paged-out, when the GC runs it has to reaload all the
pages from the paging file to perform a scan.
Funny that people are so paranoid about memory consumption these days, while
they don't seem to understand (or measure) the impact on other resources
when trying to play fast and loose with things that are much better left to
the OS and the GC itself to be done.

Good luck,
Andrey

Pete
<tr**************@yahoo.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
Hi all

I am having application in c# where i am loading one table of database
into dataset.
My table is of large size. so whenever i am loading that into dataset
my memory size is getting increased.

So what i want is as soon as i am setting dataset to null, memory
should be released.
But when i am looking into task manager for memory useage what i am
getting is same memory is till occupied by my application.

Can some one tell me how to forcefully release memory.

Please help me as this is very important for me.
Thanks in advance.

Nov 18 '05 #7
To hopefully clear up what others have said, I'll give it to you .Net memory
management at a high-level.

..Net does a lot of memory management for you (unlike many previous unmanaged
languages). When an object falls out of scope or the dispose() object is
explicitly called, it's earmarked for deletion next time garbage collection
runs. This memory is not freed up immediately though (this is what you're
experiencing).

Garbage collection runs on an "intelligent" algorithm and unless you really
research, you're not really ever supposed to call GC.Collect() yourself
because it breaks it's learning mechanism. I go ahead and do like you do
though, and I have used it a couple times after calling a HUGE memory
intensive operation that I won't ever need to do again any time soon. It
hasn't really caused any problems, so I don't worry about it.

IMPORTANT: GC.Collect() only frees up memory that's been earmarked to be
freed up though. If you're still in the same method/class/whatever where
the dataset (or whatever large object) is still in scope, NOTHING will free
up that memory until you explicitly call dispose() on the object or let it
go out of scope, and after one or the other then call GC.Collect().

Hope that helps,
Craig

<tr**************@yahoo.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
Hi all

I am having application in c# where i am loading one table of database
into dataset.
My table is of large size. so whenever i am loading that into dataset
my memory size is getting increased.

So what i want is as soon as i am setting dataset to null, memory
should be released.
But when i am looking into task manager for memory useage what i am
getting is same memory is till occupied by my application.

Can some one tell me how to forcefully release memory.

Please help me as this is very important for me.
Thanks in advance.

Nov 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: lebo | last post by:
Hi I'm trying to understand how Python handles memory usage and dynamic object loading and unloading. Problem to solve? Build a very low memory footprint (non-GUI) Python application for...
5
by: ahmadzia673 | last post by:
I am using a COM component in my ASP.Net application. When i try to release it from memory by using Marshal.ReleaseComObject, its not working. The memory is still leaks. What to do? Is there any...
2
by: M.Ob | last post by:
Hello... I am having issues with my asp.net apps not releasing memory. The memory usage for the process w3p.exe continues to grow to it's allowable limit and does not drop until the app pool is...
8
by: Sean | last post by:
I have a service that is pulling alot of records from a SQL Server table in a DataSet. This process takes up alot of memory, which is to be expected. But when the process is finished, I am clearing...
5
by: Mark Rae | last post by:
Hi, I'm encountering a strange phenomenon whereby a DataSet object is not releasing its memory when it's being disposed and/or set to Nothing. It is part of a Windows service written in VB.NET...
12
by: iker.arizmendi | last post by:
Is there any way to get Python to release memory back to the C allocator? I'm currently running a script that goes through the following steps: 1) Creates a very large number of Python objects...
5
by: Ian Boyd | last post by:
Customer is running a load test against a websphere application that uses DB2. While the load test is running the memory usage of DB2 climbs from x up to y. When the load test ends, the memory...
1
by: amollokhande1 | last post by:
Hi All, We have ASP.Net based content management web application. We are performing lots of XML based operations like setting the innerxml, loading the xml, string replace operations on XML etc....
2
by: enggwaqas | last post by:
Hi guys, I have a memory problem in my vb.net application. It's actually a point of sales system, which must be keep running the whole day. The problem is: application is not releasing any memory...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.