Main Site Documentation

Fez Hydra - CP7 - Out of memory


I have a FEZ Hydra (4.2) and a CP7 display. I have some jpg images that i am displaying on the screen for UI design and some Text. When i am operating the various functionalities, after some specific number of operations, the system goes out of memory. Is there something i need to do like dispose when i am using images and text? The error message is as follows.

GC: 12msec 4855236 bytes used, 1435896 bytes available
Type 0F (STRING ): 1884 bytes
Type 11 (CLASS ): 56364 bytes
Type 12 (VALUETYPE ): 1980 bytes
Type 13 (SZARRAY ): 8148 bytes
Type 03 (U1 ): 156 bytes
Type 04 (CHAR ): 816 bytes
Type 07 (I4 ): 1044 bytes
Type 08 (U4 ): 36 bytes
Type 0F (STRING ): 444 bytes
Type 11 (CLASS ): 5484 bytes
Type 12 (VALUETYPE ): 168 bytes
Type 15 (FREEBLOCK ): 1435896 bytes
Type 16 (CACHEDBLOCK ): 216 bytes
Type 17 (ASSEMBLY ): 31644 bytes
Type 18 (WEAKCLASS ): 96 bytes
Type 19 (REFLECTION ): 204 bytes
Type 1B (DELEGATE_HEAD ): 1116 bytes
Type 1D (OBJECT_TO_EVENT ): 288 bytes
Type 1E (BINARY_BLOB_HEAD ): 4741476 bytes
Type 1F (THREAD ): 1536 bytes
Type 20 (SUBTHREAD ): 144 bytes
Type 21 (STACK_FRAME ): 3504 bytes
Type 22 (TIMER_HEAD ): 72 bytes
Type 27 (FINALIZER_HEAD ): 2448 bytes
Type 31 (IO_PORT ): 216 bytes
Type 33 (I2C_XACTION ): 48 bytes
Type 34 (APPDOMAIN_HEAD ): 72 bytes
Type 36 (APPDOMAIN_ASSEMBLY ): 3780 bytes
Failed allocation for 5175 blocks, 62100 bytes

GC: performing heap compaction…
#### Exception System.InvalidOperationException - CLR_E_INVALID_OPERATION (6) ####
#### Message:
#### Microsoft.SPOT.Hardware.Port::ReservePin [IP: 0000] ####
#### Microsoft.SPOT.Hardware.PWM::Dispose [IP: 0017] ####
A first chance exception of type ‘System.InvalidOperationException’ occurred in Microsoft.SPOT.Hardware.dll
An unhandled exception of type ‘System.InvalidOperationException’ occurred in Microsoft.SPOT.Hardware.dll


Microsoft.SPOT.Hardware.PWM. But the problem i am stating happens just by me clicking around the screen for some configurations. I have an external switch that will fire the PWM and so on but the memory issue happens in the configuration level. If i setup a single configuration and use PWM, it works. Infact it works for 27 different configurations. When i set the 28th type then it crashes. Here configuration means me setting up the power, duration, etc… from the UI.


Looks like you are running out of memory and potentially the GC is cleaning up your PWM object. You’re likely going to have to show code. I would try to create a code sample that matches your use that can then reproduce this at will, and share that.


I am having following variable/objects in the screen

  1. One JPG for the background (99.3 KB)
  2. Another JPG in the background (64.5 KB)
  3. 5-7 Labels which can be incremented and decremented when buttons are pressed.
  4. The value of these labels are also changed from clicking on some parts of screen where presets are available.
  5. When a button “Ready” is clicked, i do some very small calculation and set 3-4 variables.
  6. The second background image is sometimes swapped with new images for different functionalities. The other images are (32.1, 32.1 and 19.6 KB respectively)

The memory problem occurs when i click on some presets and click ready for the 27th or 28th time.

Is my problem because of the images?


No the problem is because of two things. First, you fail to allocate some memory in a contiguous area of memory, so you get this:

Failed allocation for 5175 blocks, 62100 bytes

Then, the GC says well I need to compress memory into contiguous blocks and disposes of your PWM object.

You need to find out what allocation is failing - that might help you optimise that.

You need to sort out your code to hold the PWM object so it’s not disposed.

Is this related to your images? Probably. But tracking that down will need to see your code.


How will i allocate contiguous area of memory? And is there a tool i can use to see what resources are occupying memory? I can send the code if you want.


I am not going to diagnose this for you, posting your code here will be the best you can do (but SIMPLIFY it into something that shows the issue).

You can’t allocate contiguous memory; the framework does that for you. All you can do is figure out what is being created that needs that memory and see if you can optimise that.