Main Site Documentation

Cerbuino memory issues when using WiFlyGSX and GBee together


#1

I’ve got a program that receives packets from an XBee (Using GBee), accumulates them then sends an HTTP POST (json) message to our server. It works some of the time but I get a lot of “Failed allocation”, and even an occasional “System.OutOfMemoryException”. The HTTP requests it builds are sometimes quite large (2 - 4k)

Here’s an example debug output where I store 13 XBee packets in a queue, then build my json HTTP request from them:

Here’s the code leading up to the post:

          
   Debug.EnableGCMessages(true);
   Debug.GC(true);
   Debug.Print("Memory: " + Microsoft.SPOT.Debug.GC(false).ToString());

    HTTP_Client httpClient = new HTTP_Client(Socket);
    HTTP_Client.HTTP_Response Response = httpClient.Pos(Path, buildJsonBody());

Adding mesh packet from : 1123
Adding mesh packet from : 1124
Adding mesh packet from : 1125
Adding mesh packet from : 1126
Adding mesh packet from : 1127
Failed allocation for 153 blocks, 1836 bytes

Adding mesh packet from : 1128
Adding mesh packet from : 1129
Adding mesh packet from : 1130
Adding mesh packet from : 1131
Failed allocation for 274 blocks, 3288 bytes

Adding mesh packet from : 1132
Adding mesh packet from : 1133
Failed allocation for 334 blocks, 4008 bytes

Adding mesh packet from : 1134
Failed allocation for 364 blocks, 4368 bytes

Adding mesh packet from : 1135
Memory: 20412
Posting to ec2-xx-xx-xxx-xx.us-west-2.compute.amazonaws.com : json=[{… text removed for brevity - about 4k …}}]
Failed allocation for 411 blocks, 4932 bytes

Failed allocation for 411 blocks, 4932 bytes

A first chance exception of type ‘System.OutOfMemoryException’ occurred in mscorlib.dll


#2

Forcing GC before allocations should help.


#3

I’m already doing that with

Debug.GC(true);

I’ve tried adding it after as well - no help.


#4

See if you can optimize your code. Do less allocations, reuse buffers.