Bug in Garbage Collector if too many objects in compact framework

P

Palm Kevin

I observed a strange behaviour in my program.
When I create too much objects, the garbage collector seems to not be
able free the allocated memory.
Example where the GC frees memory:
ArrayList c = new ArrayList();
for(int i = 0; i < 200; i ++)
{
c.Add(new char[500000]);
}
c = null;
GC.Collect();
The free memory before loop : 27.26
The free memory after loop : 10.49
The free memory after GC : 27

In the previous example the GC freed 16.51 Mb
Now consider the following example.

ArrayList al = new ArrayList();
for(int i = 0; i < 500; i ++)
{
al.Add(new char[200000]);
}
al = null;
GC.Collect();
The free memory before loop : 27.26
The free memory after loop : 2.69
The free memory after GC : 2.69

Here the GC freed NOTHING!?

Has somebody an explication for this???
 
G

Guest

I also heard lately that the Pocket PC 2003 PDA is loosing memory as well.
Has anybody heard about a meory loss issue in PPC2003?
 
P

Paulo Pinto

Hi Everyone,

I am planning to create some toy applications
for .Net Compact Framework. Am I really required
to have Visual Studio.Net? Is there a cheaper
soluction available?

At least for J2ME I can get everything from the
developers sites.

Thanks in advance,
Paulo Pinto
 
C

Chris Tacke, eMVP

Calling GC.Collect does not force the GC to actually collect. It's more of
a "suggestion".

Trying to "profile" the GC behavior is a fairly useless activity. It has
thresholds that it adheres to and has very little exposed that allows any
modification to its behavior. Add to that the fact that the whole point of
a GC is so your app doesn't need to worry about memory. If you are actually
having memory problems, then post a question about what you're seeing,
otherwise why not let the system do what it was designed to do?
 
A

anamika

Hi ,

Use
GC.Collect()
GC.WaitForPendingFinalizers()

and see how it behaves.

Thanks

Anamika
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top