473,387 Members | 1,528 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,387 software developers and data experts.

Garbage Collector - what am I doing wrong (Windows CE)

Hello guys,

we are working on an application system for Windows CE which consists of several processes.

One of our devices only has 60 MB of RAM. It is divided in 8MB program storage and 52MB memory storage.

We have the following scenario:
Once our main application (and several small helper applications) is started 45 MB memory storage is in use.

That means only 7 MB are left. So far so good.

This main application gives the user the possibility to start several other tasks. Each task is another process.

And here comes the interesting part:
When the user tries to start one task it results in an systemoutofmemory exception. I understand, that makes sense.
BUT: When I now check the memory which is in use: it is reduced to 32MB - although the same processes are running as before.
So I guess somehow the GC must have noticed that memory is about to exceed and frees several MBs.

Another interesting fact:
When the user tries to start another task it does not result in an SOFM Exception. However, when I check the memory storage: it has been reduced to 32 MB as well - although no process has thrown an exception.

So my assumption is:
In the first scenario the GC frees memory too slow for the task that is being started. The process tries to allocate memory but fails => exception.

In the second scenario the GC frees memory fast enough so that the task can get whatever it is asking for.

Is that correct? If so: Is there a possibility to get scenario 1 working as well? Maybe a way to tell the GC to free memory earlier than usually.
(I do not want to add a timer to each process that executes GC.Collect every once in a while :-))

I hope you guys understood my problem. If not, please ask.

Thank you very much,
Kevin
Oct 6 '09 #1
2 4240
GaryTexmo
1,501 Expert 1GB
Look further into the GC class, I believe there's settings you can use to make it be a little more on top of cleaning things out. As I understand it, it's not advisable to call GC.Collect() explicitely, but if you're going to do it, do it when you actually free up memory (not on a timer).

For example, lets say you have a method that allocates a large block of data to do it's processing, at the end of the method set the reference to the array to null, then call GC.Collect().

Either way, I'd explore what the GC class has to offer (if anything) before you resort to that :)
Oct 7 '09 #2
PRR
750 Expert 512MB
"The garbage collector tracks and reclaims objects allocated in managed memory. Periodically, the garbage collector performs garbage collection to reclaim memory allocated to objects for which there are no valid references. Garbage collection happens automatically when a request for memory cannot be satisfied using available free memory." MSDN

GC is activated when the memory is low. Maybe process A requires more resources and memory therfoere throws exception. Process B also causes the GC to collect but doesn't throw error as it (maybe) requires less resources.
I would suggest you insert
Expand|Select|Wrap|Line Numbers
  1. GC.Collect();
  2. GC.WaitForPendingFinalizers();
  3.  
in your code, to free up memory and run garbage collection forcefully. However doing this you will suspend all thread till GC completes.

Also with .NET Framework 3.5 you can use
GC.WaitForFullGCComplete method, to check GC status.
Oct 7 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Nick Jacobson | last post by:
In the Python documentation on Extending and Embedding (in section 1.10), there's a quote: "Maybe some day a sufficiently portable automatic garbage collector will be available for C. Until...
10
by: pachanga | last post by:
The Hans-Boehm garbage collector can be successfully used with C and C++, but not yet a standard for C++.. Is there talks about Garbage Collector to become in the C++ standard?
2
by: Daniel Brown | last post by:
I am registering a managed delegate to an unmanaged DLL for asynchronous callback. I understand the garbage collector will free the managed resource if they go out of scope but with the...
14
by: Christian Kaiser | last post by:
We have a component that has no window. Well, no window in managed code - it uses a DLL which itself uses a window, and this is our problem! When the garbage collector runs and removes our...
13
by: Mingnan G. | last post by:
Hello everyone. I have written a garbage collector for standard C++ application. It has following main features. 1) Deterministic Finalization Providing deterministic finalization, the system...
3
by: Fab | last post by:
Hi ! Maybe somebody has used a GC - I think to Hans Boehm's one, but other, if any, are welcome -. I need to use a GC in order to program an interpreter for a functional language. Memory...
4
by: daniel.internet | last post by:
Hello, I got one question, that may seems trivial to you, but I really dont understand it. Let's say we got this code: function ajax() { var obj; obj = new...
350
by: Lloyd Bonafide | last post by:
I followed a link to James Kanze's web site in another thread and was surprised to read this comment by a link to a GC: "I can't imagine writing C++ without it" How many of you c.l.c++'ers use...
46
by: Carlo Milanesi | last post by:
Hello, traditionally, in C++, dynamically allocated memory has been managed explicitly by calling "delete" in the application code. Now, in addition to the standard library strings, containers,...
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.