473,385 Members | 1,597 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,385 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 25925
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.