But test programs from both mentioned threads work fine.
My app is quite memory consuming (uses about half of RAM, just about 3MByte are free).
It’s also using a couple of open Network connections (TCP/IP server and client), but it should be good under the maximum limit.
There are also a couple waiting (Manual)ResetEvent’s waiting in different threads.
In my test environment no network cable is connected.
Wenn a cable is connected (with some traffic from external source) some of the Debug.GC calls does not cause a freeze/reboot.
I can not remember that this happened with 126.96.36.199, but my project has grown since. I also thought that I did not have this problem at the beginning with 188.8.131.52, but at least my stability problems started shortly after the update.
If the GC runs on it’s own there is no freeze/reboot (happens every time when my data is initialized). No matter if I put a Debug.GC before or after that it will freeze/reboot.
This is a critical issue for me, because this should already run at a customer site.
Any hint is really appreciated.
I’ll play around with my program and the test program and will provide more info if I can find out more.
I got one more info on this.
Debug.GC freezes/reboots after allocating a lot of small objects (classes).
“A lot of” means thousands.
Allocating them is fine, using them is fine, but GC can not handle it!?
The objects are organized as a linked list (each one has a reference to the next one (but not back). I thought this would be better than an ArrayList (which causes an outofMemory exception, even that there is plenty free RAM). Can’t use a static array b/c I don’t know how many items I get when I start reading the file.
@ Reinhard Ostermeier - I tested your original code on a Cobra II and see same behavior as you described. Then i did some cleanup using resharper and it seems to make a difference. If you want to share your mail address i can sent you the modified file “program.cs” Maybe by comparing the sources you can see what made the difference.
@ RobvanSchelven - I think ReSharper removed the class var for the linked list root. By this none of the thousends of objects are referenced, so GC can collect them.
In fact this makes the whole program useless.
The reason why ReSharper did this is that I commented the code which uses it to avoid adding more code to the program, which is not related to the Problem.
I have stripped down the code to the absolute minimum:
public class Program
public static void Main()
// give debugger a chance to attach in endles reboot loop
var loader1 = new Loader();
// this GC is always ok
var loader2 = new Loader();
// this GC always freezes/reboots
// we never get here
public class Loader
public void CreateSome()
_First = null;
KmaParam last = null;
// it doesn't matter if i create 200 or 5000 items per linked list, GC always fails after 2nd list is created!
// at 130 the 2nd GC is OK, at 140 it fails
for (int n = 0; n < 200; ++n)
var param = new KmaParam();
if (last == null)
_First = param;
last.Next = param;
last = param;
private KmaParam _First;
internal class KmaParam
internal KmaParam Next;
// if field is removed then GC does not freeze/reboot !?
public int TelegramNo;
No SD card, external files to read or complex objects are involved anymore.
It looks like as if GC has a huge problems with linked lists
Also memory usage is way down in this sample, so this is not the reason I think
Would really be nice if GHI could look into this.
@ Dat - Jep
I have a lot of small objects. I create them by reading a file from SD.
I don’t know how many I’ll get.
So I used an ArrayList at first.
Then IO got an OutOfMemory exception. Looks like every object reference in ArrayList needs 12 Bytes.
So I made it a linked list.
But GC can not handle a linked list in memory.
Any Ideas how to do this.
I thought of an ArrayList which contains arrays of my objects.
With thousands of objects GC might be running out of memory. Might be due to the way GC determines if objects are still being referenced. Recursion might be used, resulting in memory overflow. Time to look at the code in the porting kit.
Might be worth while to chain blocks, each containing multiple objects, resulting in a shorter chain.
You might want to try to increase the capacity of an ArrayList right after creation to the maximum number of object to be supported. Will avoid memory issues due to dynamically increasing the capacity of the ArrayList.
@ Reinhard Ostermeier - When you use ArrayList, remember that .NETMF has a limit of +/-700KB (closer to 800 actually) for a single allocation and an array is a single allocation.
Internally ArrayList has a object so the total number of elements in the array should not exceed the 700KB limit otherwise you will get an allocation failure even though you have more than enough memory.
Fortunately they array is an array of references so you should be able to get about 60,000 - 65,000 element object, that is of course disregarding the size of the actual elements which will not be counted towards the single allocation limit, but will of course consume main memory.
For example, assuming you have an ArrayList called values and one of the devices with lots of memory like the Spider, G400, Raptor, Hydra etc.
This will work (can probably get a little more than 65000) at around 760KB
values = new ArrayList();
values.Capacity = 65000;
But this will fail with an OutOfMemoryException even though there is actually plenty of memory.
values = new ArrayList();
values.Capacity = 67000;
I used capacity in the sample above, the same applies if you just let the array list dynamically grow.
@ taylorza - I’m aware of the Capacity property, but it’s hard to set it if you don’t know how many items you well get in advance (don’t want to loose too much RAM.
In my case it caused a OutOfMemoryExeption on add telling me: (numbers are not exact)
"Allocating 2748 Block: 33000 Bytes"
This means to me: ArrayList wanted to allocate an array of 2748 elements, which would use 33000 Bytes.
By this each element (object reference) uses 12 Bytes.
What I don’t understand here is that 33k is less then half of the limit, And I had 3MByte available RAM. So it must be fragmentation which caused that exception.