Problem with Type 13 (SZARRAY)

Hello every one !
first of all sorry if i made mistake i’m french ^^

So i use code exemple in the ebook " internet of thing", that great but i try to modify a little.

Now i have a problem in the GC => Type 13 (SZARRAY) take more and more space and so the card do not answer …

here is the code :

using System;
using System.Threading;
using System.Text;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.Hardware;
using GHIElectronics.NETMF.Net;
using GHIElectronics.NETMF.Net.NetworkInformation;
public class Program
{
    public static void Main()
    {



        OutputPort red = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di2, false);
        OutputPort green = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di3, false);
        OutputPort yellow = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di1, false);

        green.Write(false);
        string ValeurLedVerte = "allumer";
        string LectureLedVerte = "eteint";

        yellow.Write(false);
        string ValeurLedOrange = "allumer";
        string LectureLedOrange = "eteint";

        red.Write(false);
        string ValeurLedRouge = "allumer";
        string LectureLedRouge = "eteint";




        PWM piezo = new PWM((PWM.Pin)FEZ_Pin.PWM.Di5);
        byte[] ip = { 192, 168, 0, 200 };
        byte[] subnet = { 255, 255, 255, 0 };
        byte[] gateway = { 192, 168, 1, 1 };
        byte[] mac = { 0x00, 0x88, 0x98, 0x90, 0xD4, 0xE0 };
        WIZnet_W5100.Enable(SPI.SPI_module.SPI1, (Cpu.Pin)FEZ_Pin.Digital.Di10, (Cpu.Pin)FEZ_Pin.Digital.Di7, true);
        NetworkInterface.EnableStaticIP(ip, subnet, gateway, mac);
        NetworkInterface.EnableStaticDns(gateway);
        // start server
        HttpListener listener = new HttpListener("http", 80);

        
         




        listener.Start();
        while (true)
        {
            HttpListenerResponse response = null;
            HttpListenerContext context = null;
            HttpListenerRequest request = null;
            try
            {
                context = listener.GetContext();
                response = context.Response;
                request = context.Request;

                // si un bouton est pressé
                if (context.Request.HttpMethod == "POST")
                {

                    if (request.ContentLength64 > 0)
                    {
                        Debug.GC(true);
                        // on lis le "name" des bouton + les "value"
                        byte[] buffer = new byte[(int)request.ContentLength64];
                        request.InputStream.Read(buffer, 0, (int)request.ContentLength64);
                        string actionAeffectuer = new string(Encoding.UTF8.GetChars(buffer));
                        
                        // la variable actionAeffectuer contient "name"="value"
                        int index = actionAeffectuer.IndexOf('='); // on obtient la place de "="
                        actionAeffectuer = actionAeffectuer.Substring(0, index); // on découpe la variable actionAeffectuer pour ne récuperer tout ce qu'il y a avant le "="
                        
                        //et maintenant on peut tester l'action a effectuer !!
                        if (actionAeffectuer == "volet")
                        {
                            if (green.Read() == true)
                            {
                                green.Write(false);
                                ValeurLedVerte = "allumer";
                                LectureLedVerte = "eteint";
                            }

                            else
                            {
                                green.Write(true);
                                ValeurLedVerte = "eteindre";
                                LectureLedVerte = "allumer";

                            }

                        }

                        if (actionAeffectuer == "porte")
                        {
                            if (yellow.Read() == true)
                            {
                                yellow.Write(false);
                                ValeurLedOrange = "allumer";
                                LectureLedOrange = "eteint";
                            }

                            else
                            {
                                yellow.Write(true);
                                ValeurLedOrange = "eteindre";
                                LectureLedOrange = "allumer";

                            }
                        }

                        if (actionAeffectuer == "heat")
                        {
                            if (red.Read() == true)
                            {
                                red.Write(false);
                                ValeurLedRouge = "allumer";
                                LectureLedRouge = "eteint";
                            }

                            else
                            {
                                red.Write(true);
                                ValeurLedRouge = "eteindre";
                                LectureLedRouge = "allumer";
                            }

                        }

                        
                      /*  buffer = null;*/
                    }

                    
                }
                // Sends response
                response.StatusCode = (int)HttpStatusCode.OK;
                byte[] HTML = Encoding.UTF8.GetBytes(
                "<html><body>" +
                "<h1>Hosted on FEZ Panda II</h1>" +

                "<form action=\"\" method=\"post\">" +
                "<p>led verte :<input type=\"submit\" name=\"volet\" value=\"" + ValeurLedVerte + "\">  la led est actuellement " + LectureLedVerte + ".</p>" +
                "<p>led orange :<input type=\"submit\" name=\"porte\" value=\"" + ValeurLedOrange + "\">  la led est actuellement " + LectureLedOrange + ".</p>" +
                "<p>led rouge :<input type=\"submit\" name=\"heat\" value=\"" + ValeurLedRouge + "\">  la led est actuellement " + LectureLedRouge + ".</p>" +
                "</form>" +
                "</body></html>");
                response.ContentType = "text/html";
                response.OutputStream.Write(HTML, 0, HTML.Length);
                response.Close();

             /*   ValeurLedVerte = null;
                ValeurLedOrange = null;
                ValeurLedRouge = null;
                LectureLedVerte = null;
                LectureLedOrange = null;
                LectureLedRouge = null;*/

              /*  response = null;
                context = null;
                request = null;*/

            }
            catch
            {
                if (context != null)
                {
                    context.Close();
                }
            }
        }
    }
}

and here is a sample of the error

GC: 3msec 30084 bytes used, 34296 bytes available
Type 0F (STRING ): 1260 bytes
Type 11 (CLASS ): 4416 bytes
Type 12 (VALUETYPE ): 600 bytes
Type 13 (SZARRAY ): 3120 bytes
Type 15 (FREEBLOCK ): 34296 bytes
Type 16 (CACHEDBLOCK ): 72 bytes
Type 17 (ASSEMBLY ): 15240 bytes
Type 18 (WEAKCLASS ): 48 bytes
Type 19 (REFLECTION ): 24 bytes
Type 1B (DELEGATE_HEAD ): 252 bytes
Type 1D (OBJECT_TO_EVENT ): 168 bytes
Type 1E (BINARY_BLOB_HEAD ): 156 bytes
Type 1F (THREAD ): 384 bytes
Type 20 (SUBTHREAD ): 48 bytes
Type 21 (STACK_FRAME ): 2076 bytes
Type 22 (TIMER_HEAD ): 72 bytes
Type 27 (FINALIZER_HEAD ): 312 bytes
Type 31 (IO_PORT ): 216 bytes
Type 34 (APPDOMAIN_HEAD ): 72 bytes
Type 36 (APPDOMAIN_ASSEMBLY ): 1548 bytes
GC: 3msec 32220 bytes used, 32160 bytes available
Type 0F (STRING ): 1644 bytes
Type 11 (CLASS ): 5424 bytes
Type 12 (VALUETYPE ): 528 bytes
Type 13 (SZARRAY ): 4776 bytes
Type 15 (FREEBLOCK ): 32160 bytes
Type 17 (ASSEMBLY ): 15240 bytes
Type 18 (WEAKCLASS ): 48 bytes
Type 19 (REFLECTION ): 24 bytes
Type 1B (DELEGATE_HEAD ): 288 bytes
Type 1D (OBJECT_TO_EVENT ): 168 bytes
Type 1E (BINARY_BLOB_HEAD ): 156 bytes
Type 1F (THREAD ): 384 bytes
Type 20 (SUBTHREAD ): 48 bytes
Type 21 (STACK_FRAME ): 1224 bytes
Type 22 (TIMER_HEAD ): 72 bytes
Type 27 (FINALIZER_HEAD ): 360 bytes
Type 31 (IO_PORT ): 216 bytes
Type 34 (APPDOMAIN_HEAD ): 72 bytes
Type 36 (APPDOMAIN_ASSEMBLY ): 1548 bytes
GC: 3msec 31404 bytes used, 32976 bytes available
Type 0F (STRING ): 1536 bytes
Type 11 (CLASS ): 5460 bytes
Type 12 (VALUETYPE ): 528 bytes
Type 13 (SZARRAY ): 4608 bytes
Type 15 (FREEBLOCK ): 32976 bytes
Type 17 (ASSEMBLY ): 15240 bytes
Type 18 (WEAKCLASS ): 48 bytes
Type 19 (REFLECTION ): 24 bytes
Type 1B (DELEGATE_HEAD ): 288 bytes
Type 1D (OBJECT_TO_EVENT ): 168 bytes
Type 1E (BINARY_BLOB_HEAD ): 156 bytes
Type 1F (THREAD ): 384 bytes
Type 20 (SUBTHREAD ): 48 bytes
Type 21 (STACK_FRAME ): 648 bytes
Type 22 (TIMER_HEAD ): 72 bytes
Type 27 (FINALIZER_HEAD ): 360 bytes
Type 31 (IO_PORT ): 216 bytes
Type 34 (APPDOMAIN_HEAD ): 72 bytes
Type 36 (APPDOMAIN_ASSEMBLY ): 1548 bytes
GC: 3msec 34704 bytes used, 29676 bytes available
Type 0F (STRING ): 1440 bytes
Type 11 (CLASS ): 6108 bytes
Type 12 (VALUETYPE ): 528 bytes
Type 13 (SZARRAY ): 6120 bytes
Type 15 (FREEBLOCK ): 29676 bytes
Type 17 (ASSEMBLY ): 15240 bytes
Type 18 (WEAKCLASS ): 48 bytes
Type 19 (REFLECTION ): 24 bytes
Type 1B (DELEGATE_HEAD ): 288 bytes
Type 1D (OBJECT_TO_EVENT ): 168 bytes
Type 1E (BINARY_BLOB_HEAD ): 156 bytes
Type 1F (THREAD ): 384 bytes
Type 20 (SUBTHREAD ): 48 bytes
Type 21 (STACK_FRAME ): 1836 bytes
Type 22 (TIMER_HEAD ): 72 bytes
Type 27 (FINALIZER_HEAD ): 408 bytes
Type 31 (IO_PORT ): 216 bytes
Type 34 (APPDOMAIN_HEAD ): 72 bytes
Type 36 (APPDOMAIN_ASSEMBLY ): 1548 bytes
GC: 3msec 33744 bytes used, 30636 bytes available
Type 0F (STRING ): 1560 bytes
Type 11 (CLASS ): 6252 bytes
Type 12 (VALUETYPE ): 528 bytes
Type 13 (SZARRAY ): 6084 bytes
Type 15 (FREEBLOCK ): 30636 bytes
Type 17 (ASSEMBLY ): 15240 bytes
Type 18 (WEAKCLASS ): 48 bytes
Type 19 (REFLECTION ): 24 bytes
Type 1B (DELEGATE_HEAD ): 288 bytes
Type 1D (OBJECT_TO_EVENT ): 168 bytes
Type 1E (BINARY_BLOB_HEAD ): 156 bytes
Type 1F (THREAD ): 384 bytes
Type 20 (SUBTHREAD ): 48 bytes
Type 21 (STACK_FRAME ): 648 bytes
Type 22 (TIMER_HEAD ): 72 bytes
Type 27 (FINALIZER_HEAD ): 408 bytes
Type 31 (IO_PORT ): 216 bytes
Type 34 (APPDOMAIN_HEAD ): 72 bytes
Type 36 (APPDOMAIN_ASSEMBLY ): 1548 bytes
GC: 3msec 36912 bytes used, 27468 bytes available
Type 0F (STRING ): 1296 bytes
Type 11 (CLASS ): 6864 bytes
Type 12 (VALUETYPE ): 528 bytes
Type 13 (SZARRAY ): 7740 bytes
Type 15 (FREEBLOCK ): 27468 bytes
Type 17 (ASSEMBLY ): 15240 bytes
Type 18 (WEAKCLASS ): 48 bytes
Type 19 (REFLECTION ): 24 bytes
Type 1B (DELEGATE_HEAD ): 288 bytes
Type 1D (OBJECT_TO_EVENT ): 168 bytes
Type 1E (BINARY_BLOB_HEAD ): 156 bytes
Type 1F (THREAD ): 384 bytes
Type 20 (SUBTHREAD ): 48 bytes
Type 21 (STACK_FRAME ): 1764 bytes
Type 22 (TIMER_HEAD ): 72 bytes
Type 27 (FINALIZER_HEAD ): 456 bytes
Type 31 (IO_PORT ): 216 bytes
Type 34 (APPDOMAIN_HEAD ): 72 bytes
Type 36 (APPDOMAIN_ASSEMBLY ): 1548 bytes
GC: 3msec 36036 bytes used, 28344 bytes available
Type 0F (STRING ): 1560 bytes
Type 11 (CLASS ): 7044 bytes
Type 12 (VALUETYPE ): 528 bytes
Type 13 (SZARRAY ): 7536 bytes
Type 15 (FREEBLOCK ): 28344 bytes
Type 17 (ASSEMBLY ): 15240 bytes
Type 18 (WEAKCLASS ): 48 bytes
Type 19 (REFLECTION ): 24 bytes
Type 1B (DELEGATE_HEAD ): 288 bytes
Type 1D (OBJECT_TO_EVENT ): 168 bytes
Type 1E (BINARY_BLOB_HEAD ): 156 bytes
Type 1F (THREAD ): 384 bytes
Type 20 (SUBTHREAD ): 48 bytes
Type 21 (STACK_FRAME ): 648 bytes
Type 22 (TIMER_HEAD ): 72 bytes
Type 27 (FINALIZER_HEAD ): 456 bytes
Type 31 (IO_PORT ): 216 bytes
Type 34 (APPDOMAIN_HEAD ): 72 bytes
Type 36 (APPDOMAIN_ASSEMBLY ): 1548 bytes
GC: 3msec 38328 bytes used, 26052 bytes available
Type 0F (STRING ): 1248 bytes
Type 11 (CLASS ): 7584 bytes
Type 12 (VALUETYPE ): 528 bytes
Type 13 (SZARRAY ): 8976 bytes
Type 15 (FREEBLOCK ): 26052 bytes
Type 17 (ASSEMBLY ): 15240 bytes
Type 18 (WEAKCLASS ): 48 bytes
Type 19 (REFLECTION ): 24 bytes
Type 1B (DELEGATE_HEAD ): 288 bytes
Type 1D (OBJECT_TO_EVENT ): 168 bytes
Type 1E (BINARY_BLOB_HEAD ): 156 bytes
Type 1F (THREAD ): 384 bytes
Type 20 (SUBTHREAD ): 48 bytes
Type 21 (STACK_FRAME ): 1224 bytes
Type 22 (TIMER_HEAD ): 72 bytes
Type 27 (FINALIZER_HEAD ): 504 bytes
Type 31 (IO_PORT ): 216 bytes
Type 34 (APPDOMAIN_HEAD ): 72 bytes
Type 36 (APPDOMAIN_ASSEMBLY ): 1548 bytes
GC: 3msec 38316 bytes used, 26064 bytes available
Type 0F (STRING ): 1560 bytes
Type 11 (CLASS ): 7836 bytes
Type 12 (VALUETYPE ): 528 bytes
Type 13 (SZARRAY ): 8976 bytes
Type 15 (FREEBLOCK ): 26064 bytes
Type 17 (ASSEMBLY ): 15240 bytes
Type 18 (WEAKCLASS ): 48 bytes
Type 19 (REFLECTION ): 24 bytes
Type 1B (DELEGATE_HEAD ): 288 bytes
Type 1D (OBJECT_TO_EVENT ): 168 bytes
Type 1E (BINARY_BLOB_HEAD ): 156 bytes
Type 1F (THREAD ): 384 bytes
Type 20 (SUBTHREAD ): 48 bytes
Type 21 (STACK_FRAME ): 648 bytes
Type 22 (TIMER_HEAD ): 72 bytes
Type 27 (FINALIZER_HEAD ): 504 bytes
Type 31 (IO_PORT ): 216 bytes
Type 34 (APPDOMAIN_HEAD ): 72 bytes
Type 36 (APPDOMAIN_ASSEMBLY ): 1548 bytes
GC: 3msec 40248 bytes used, 24132 bytes available
Type 0F (STRING ): 1020 bytes
Type 11 (CLASS ): 8340 bytes
Type 12 (VALUETYPE ): 528 bytes
Type 13 (SZARRAY ): 10320 bytes
Type 15 (FREEBLOCK ): 24132 bytes
Type 17 (ASSEMBLY ): 15240 bytes
Type 18 (WEAKCLASS ): 48 bytes
Type 19 (REFLECTION ): 24 bytes
Type 1B (DELEGATE_HEAD ): 288 bytes
Type 1D (OBJECT_TO_EVENT ): 168 bytes
Type 1E (BINARY_BLOB_HEAD ): 156 bytes
Type 1F (THREAD ): 384 bytes
Type 20 (SUBTHREAD ): 48 bytes
Type 21 (STACK_FRAME ): 1224 bytes
Type 22 (TIMER_HEAD ): 72 bytes
Type 27 (FINALIZER_HEAD ): 552 bytes
Type 31 (IO_PORT ): 216 bytes
Type 34 (APPDOMAIN_HEAD ): 72 bytes
Type 36 (APPDOMAIN_ASSEMBLY ): 1548 bytes
GC: 3msec 40596 bytes used, 23784 bytes available
Type 0F (STRING ): 1560 bytes
Type 11 (CLASS ): 8628 bytes
Type 12 (VALUETYPE ): 528 bytes
Type 13 (SZARRAY ): 10416 bytes
Type 15 (FREEBLOCK ): 23784 bytes
Type 17 (ASSEMBLY ): 15240 bytes
Type 18 (WEAKCLASS ): 48 bytes
Type 19 (REFLECTION ): 24 bytes
Type 1B (DELEGATE_HEAD ): 288 bytes
Type 1D (OBJECT_TO_EVENT ): 168 bytes
Type 1E (BINARY_BLOB_HEAD ): 156 bytes
Type 1F (THREAD ): 384 bytes
Type 20 (SUBTHREAD ): 48 bytes
Type 21 (STACK_FRAME ): 648 bytes
Type 22 (TIMER_HEAD ): 72 bytes
Type 27 (FINALIZER_HEAD ): 552 bytes
Type 31 (IO_PORT ): 216 bytes
Type 34 (APPDOMAIN_HEAD ): 72 bytes
Type 36 (APPDOMAIN_ASSEMBLY ): 1548 bytes
GC: 3msec 42420 bytes used, 21960 bytes available
Type 0F (STRING ): 828 bytes
Type 11 (CLASS ): 9024 bytes
Type 12 (VALUETYPE ): 528 bytes
Type 13 (SZARRAY ): 11748 bytes
Type 15 (FREEBLOCK ): 21960 bytes
Type 17 (ASSEMBLY ): 15240 bytes
Type 18 (WEAKCLASS ): 48 bytes
Type 19 (REFLECTION ): 24 bytes
Type 1B (DELEGATE_HEAD ): 288 bytes
Type 1D (OBJECT_TO_EVENT ): 168 bytes
Type 1E (BINARY_BLOB_HEAD ): 156 bytes
Type 1F (THREAD ): 384 bytes
Type 20 (SUBTHREAD ): 48 bytes
Type 21 (STACK_FRAME ): 1428 bytes
Type 22 (TIMER_HEAD ): 72 bytes
Type 27 (FINALIZER_HEAD ): 600 bytes
Type 31 (IO_PORT ): 216 bytes
Type 34 (APPDOMAIN_HEAD ): 72 bytes
Type 36 (APPDOMAIN_ASSEMBLY ): 1548 bytes
GC: 3msec 42864 bytes used, 21516 bytes available
Type 0F (STRING ): 1560 bytes
Type 11 (CLASS ): 9420 bytes
Type 12 (VALUETYPE ): 528 bytes
Type 13 (SZARRAY ): 11844 bytes
Type 15 (FREEBLOCK ): 21516 bytes
Type 17 (ASSEMBLY ): 15240 bytes
Type 18 (WEAKCLASS ): 48 bytes
Type 19 (REFLECTION ): 24 bytes
Type 1B (DELEGATE_HEAD ): 288 bytes
Type 1D (OBJECT_TO_EVENT ): 168 bytes
Type 1E (BINARY_BLOB_HEAD ): 156 bytes
Type 1F (THREAD ): 384 bytes
Type 20 (SUBTHREAD ): 48 bytes
Type 21 (STACK_FRAME ): 648 bytes
Type 22 (TIMER_HEAD ): 72 bytes
Type 27 (FINALIZER_HEAD ): 600 bytes
Type 31 (IO_PORT ): 216 bytes
Type 34 (APPDOMAIN_HEAD ): 72 bytes
Type 36 (APPDOMAIN_ASSEMBLY ): 1548 bytes
GC: 3msec 43008 bytes used, 21372 bytes available
Type 0F (STRING ): 552 bytes
Type 11 (CLASS ): 9264 bytes
Type 12 (VALUETYPE ): 528 bytes
Type 13 (SZARRAY ): 12960 bytes
Type 15 (FREEBLOCK ): 21372 bytes
Type 17 (ASSEMBLY ): 15240 bytes
Type 18 (WEAKCLASS ): 48 bytes
Type 19 (REFLECTION ): 24 bytes
Type 1B (DELEGATE_HEAD ): 252 bytes
Type 1D (OBJECT_TO_EVENT ): 168 bytes
Type 1E (BINARY_BLOB_HEAD ): 156 bytes
Type 1F (THREAD ): 384 bytes
Type 20 (SUBTHREAD ): 48 bytes
Type 21 (STACK_FRAME ): 852 bytes
Type 22 (TIMER_HEAD ): 72 bytes
Type 27 (FINALIZER_HEAD ): 624 bytes
Type 31 (IO_PORT ): 216 bytes
Type 34 (APPDOMAIN_HEAD ): 72 bytes
Type 36 (APPDOMAIN_ASSEMBLY ): 1548 bytes
GC: 3msec 45144 bytes used, 19236 bytes available
Type 0F (STRING ): 1560 bytes
Type 11 (CLASS ): 10212 bytes
Type 12 (VALUETYPE ): 528 bytes
Type 13 (SZARRAY ): 13284 bytes
Type 15 (FREEBLOCK ): 19236 bytes
Type 17 (ASSEMBLY ): 15240 bytes
Type 18 (WEAKCLASS ): 48 bytes
Type 19 (REFLECTION ): 24 bytes
Type 1B (DELEGATE_HEAD ): 288 bytes
Type 1D (OBJECT_TO_EVENT ): 168 bytes
Type 1E (BINARY_BLOB_HEAD ): 156 bytes
Type 1F (THREAD ): 384 bytes
Type 20 (SUBTHREAD ): 48 bytes
Type 21 (STACK_FRAME ): 648 bytes
Type 22 (TIMER_HEAD ): 72 bytes
Type 27 (FINALIZER_HEAD ): 648 bytes
Type 31 (IO_PORT ): 216 bytes
Type 34 (APPDOMAIN_HEAD ): 72 bytes
Type 36 (APPDOMAIN_ASSEMBLY ): 1548 bytes
GC: 3msec 46356 bytes used, 18024 bytes available
Type 0F (STRING ): 1272 bytes
Type 11 (CLASS ): 10440 bytes
Type 12 (VALUETYPE ): 528 bytes
Type 13 (SZARRAY ): 13956 bytes
Type 15 (FREEBLOCK ): 18024 bytes
Type 17 (ASSEMBLY ): 15240 bytes
Type 18 (WEAKCLASS ): 48 bytes
Type 19 (REFLECTION ): 24 bytes
Type 1B (DELEGATE_HEAD ): 252 bytes
Type 1D (OBJECT_TO_EVENT ): 168 bytes
Type 1E (BINARY_BLOB_HEAD ): 156 bytes
Type 1F (THREAD ): 384 bytes
Type 20 (SUBTHREAD ): 48 bytes
Type 21 (STACK_FRAME ): 1260 bytes
Type 22 (TIMER_HEAD ): 72 bytes
Type 27 (FINALIZER_HEAD ): 672 bytes
Type 31 (IO_PORT ): 216 bytes
Type 34 (APPDOMAIN_HEAD ): 72 bytes
Type 36 (APPDOMAIN_ASSEMBLY ): 1548 bytes

and after that ( you can see that szarray grow up) :

Exception System.OutOfMemoryException - CLR_E_OUT_OF_MEMORY (1)

#### Message: 
#### GHIElectronics.NETMF.Net.W5100::RegisterRead [IP: 0014] ####
#### GHIElectronics.NETMF.Net.W5100::getSn_RX_RSR [IP: 000a] ####
#### GHIElectronics.NETMF.Net.SocketNative::poll [IP: 0053] ####
#### GHIElectronics.NETMF.Net.SocketNative::recv [IP: 000c] ####
#### GHIElectronics.NETMF.Net.Sockets.Socket::Receive [IP: 0029] ####
#### GHIElectronics.NETMF.Net.Sockets.NetworkStream::Read [IP: 004d] ####
#### GHIElectronics.NETMF.Net.InputNetworkStreamWrapper::RefillInternalBuffer [IP: 0038] ####
#### GHIElectronics.NETMF.Net.InputNetworkStreamWrapper::Read_HTTP_Line [IP: 004b] ####
#### GHIElectronics.NETMF.Net.InputNetworkStreamWrapper::Read_HTTP_Header [IP: 0005] ####
#### GHIElectronics.NETMF.Net.HttpListenerRequest::ParseHTTPRequest [IP: 0170] ####
#### GHIElectronics.NETMF.Net.HttpListenerContext::get_Response [IP: 000d] ####
#### Program::Main [IP: 00cd] ####

I know that there is a lot of thing to read …
So thank you!

OOMs are not uncommon when using networking and USBizi based boards. The issue you’re hitting is most likely needing to allocate contiguous space but being unable to find this.

You can force the GC to clean up and hopefully readjust available space for you. Use a code block like this:

			Debug.GC(true);
			Debug.Print("Free mem : " + Debug.GC(false).ToString());

The Debug.GC(True) forces GC to run, and then the (false) shows the available free memory. See if that assists; I’d add it in your HTTP loop.

What firmware version are you running? 4.1?

yes - its a usbizi Wiz5100 which doesn’t have 4.2 support

@ Brett it still the same …
the mem decrease each time i press a button …

thank for help !

where did you add it?

I had it in the

while(true)

and in the

if( request == "POST")

I try to had it every where but it dosen’t work …

nobody have idea ?

i’m very lost …

thanks.

So the problem is in your code, unfortunately. It’s probably too big for most people to delve into and see where you’re leaking objects and where you could clean up and avoid this.

Jasdev has a really stable footprint web server at http://www.tinyclr.com/codeshare/entry/363 so I would suggest you take a look at his code. It’s pretty simple to expand for your case - and if nothing else you can look at how his code works in the same area and you can maybe get some tips to optimise your code.

Sorry for the above post… I clicked the quick post button by accident !

Thanks Brett :slight_smile:

@ Spoko - In your while loop you are doing a lot of buffer allocation and re-allocation:


    byte[] buffer = new byte[(int)request.ContentLength64];
     request.InputStream.Read(buffer, 0, (int)request.ContentLength64);
     string actionAeffectuer = new string(Encoding.UTF8.GetChars(buffer));
 
    // la variable actionAeffectuer contient "name"="value"
     int index = actionAeffectuer.IndexOf('='); // on obtient la place de "="
    actionAeffectuer = actionAeffectuer.Substring(0, index);

I would suggest that you allocate a fixed byte buffer before you enter the while loop that is larger than the largest content length you are expecting, and then call the Read method like this:


     bytesRead = request.InputStream.Read(buffer, 0, buffer.Length);
 

Then
[ol]use bytesRead to do a sequential search (using a for loop) for your ‘=’ character to determine the index.
convert only the bytes up to the index position to a string[/ol]

i think jasdev probably has the right fix (or one of them).

also, i’m not sure about how .netmf compiler will treat this code:

        while (true)
        {
            HttpListenerResponse response = null;
            HttpListenerContext context = null;
            HttpListenerRequest request = null;
            ....
            ....
         }

to be safe, i’d probably move that outside the loop as well, just in case new instances are being allocated each loop…

EDIT: just looked at the documentation for system.net.HttpListenerContext and I see that it implements Finalize. This means that this object is going to survive the first garbage collection at the very least and live on to gen1. so i think if that loop is assigning new instances, and given that finalization is indeterminate…then it is likely you have memory claimed by those objects living on longer than you want.

@ jasdev

i don’t understand what you mean …

but bytesRead is an “int” …

@ dizzy
i try what you say but it’s still the same …

@ Brett

this project was too big for me but i will try it.

thnaks a lot for every body !!

I think @ Jasdev is saying do a loop from 0 to readBytes, check if the character is “=”

hello !

i understand what jasdev say so i try it but it was the same …

so i try this code =>

using System;
using System.Threading;
using System.Text;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.Hardware;
using GHIElectronics.NETMF.Net;
using GHIElectronics.NETMF.Net.NetworkInformation;
public class Program
{
    public static void Main()
    {



        OutputPort green = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di3, false);


        green.Write(false);



        PWM piezo = new PWM((PWM.Pin)FEZ_Pin.PWM.Di5);
        byte[] ip = { 192, 168, 0, 100 };
        byte[] subnet = { 255, 255, 255, 0 };
        byte[] gateway = { 192, 168, 1, 1 };
        byte[] mac = { 0x00, 0x88, 0x98, 0x90, 0xD4, 0xE0 };
        WIZnet_W5100.Enable(SPI.SPI_module.SPI1, (Cpu.Pin)FEZ_Pin.Digital.Di10, (Cpu.Pin)FEZ_Pin.Digital.Di7, true);
        NetworkInterface.EnableStaticIP(ip, subnet, gateway, mac);
        NetworkInterface.EnableStaticDns(gateway);
        // start server
        HttpListener listener = new HttpListener("http", 80);







        listener.Start();
        while (true)
        {


            HttpListenerResponse response = null;
            HttpListenerContext context = null;
            HttpListenerRequest request = null;
            try
            {


                context = listener.GetContext();
                response = context.Response;
                request = context.Request;

                // si un bouton est pressé
                if (context.Request.HttpMethod == "POST")
                {


                    if (request.ContentLength64 > 0)
                    {



                        string actionAeffectuer = "volet";

                        if (actionAeffectuer == "volet")
                        {
                            if (green.Read() == true)
                            {
                                green.Write(false);
                                ;
                            }

                            else
                            {
                                green.Write(true);
                               
                            }

                        }

                    }
                    context = null;
                    request = null;

                }



                // Sends response
                response.StatusCode = (int)HttpStatusCode.OK;
                byte[] HTML = Encoding.UTF8.GetBytes(
                "<html><body>" +
                "<h1>Hosted on FEZ Panda II</h1>" +

                "<form action=\"\" method=\"post\">" +
                "<p>led verte :<input type=\"submit\" name=\"volet\" value=\"volet\">.</p>" +
                "</form>" +
                "</body></html>");
                response.ContentType = "text/html";
                response.OutputStream.Write(HTML, 0, HTML.Length);
                response.Close();

                response = null;
                context = null;
                request = null;

            }
            catch
            {
                if (context != null)
                {
                    context.Close();
                }
            }
        }
    }
}

but i have style the same problem
after something like 20 hit on the web page of the button i have an outofmemory …

I don’t know what i can do more …

thanks for reading.

i’m going to burn my FEZ PANDA ^^
please help me …

Sorry … I’ve not read through the whole thread, just the error your getting about (out of memory).

(I don’t have a board in front of me, so these are just off the top of the head observations)

  • Have you tried forcing the Garbage Collection after you set your references to null?
  • Do you you call Dispose() on the disposable objects?
  • Since you are always returning the same static data in your response, how about making that a const? (unless that’s just for testing)

@ mhectorgato

i try this

using System;
using System.Threading;
using System.Text;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.Hardware;
using GHIElectronics.NETMF.Net;
using GHIElectronics.NETMF.Net.NetworkInformation;
public class Program
{
    public static void Main()
    {



        OutputPort green = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di3, false);


        green.Write(false);


        byte[] HTML = Encoding.UTF8.GetBytes(
                "<html><body>" +
                "<h1>Hosted on FEZ Panda II</h1>" +

                "<form action=\"\" method=\"post\">" +
                "<p>led verte :<input type=\"submit\" name=\"volet\" value=\"volet\">.</p>" +
                "</form>" +
                "</body></html>");



        
        byte[] ip = { 192, 168, 2, 248 };
        byte[] subnet = { 255, 255, 255, 0 };
        byte[] gateway = { 192, 168, 1, 1 };
        byte[] mac = { 0x00, 0x88, 0x98, 0x90, 0xD4, 0xE0 };
        WIZnet_W5100.Enable(SPI.SPI_module.SPI1, (Cpu.Pin)FEZ_Pin.Digital.Di10, (Cpu.Pin)FEZ_Pin.Digital.Di7, false);
        NetworkInterface.EnableStaticIP(ip, subnet, gateway, mac);
        
        // start server
        HttpListener listener = new HttpListener("http", 80);

        listener.Start();
        while (true)
        {


            HttpListenerResponse response = null;
            HttpListenerContext context = null;
            HttpListenerRequest request = null;
            try
            {
                context = listener.GetContext();
                response = context.Response;
                request = context.Request;

                // si un bouton est pressé
                if (context.Request.HttpMethod == "POST")
                {

                            Debug.GC(true);
                            if (green.Read() == true)
                            {
                                green.Write(false);
                            }

                            else
                            {
                                green.Write(true);
                            }
                    
                    context = null;
                    request = null;

                }



                // Sends response
                response.StatusCode = 200;
                response.ContentType = "text/html";
                response.OutputStream.Write(HTML, 0, HTML.Length);
                response.Close();


                
                context = null;
                request = null;
                Debug.GC(true);

            }
            catch
            {
                if (context != null)
                {
                    context.Close();
                }
            }
        }
    }
}

but the out of memories come faster …

I don’t know what is Dispose() ?

[EDIT]
i found Dispose(), i try it and come back to say if it work
THANKS !!!
[\EDIT]

I suggest that you wrap the Panda in an old newspaper, douse with a flammable liquid, and then ignite.

Please mark your question as answered. :slight_smile:

2 Likes

I can’t use Dispose(), it say to me that maybe it miss an using or an assembly.

I try it on :

HTML

context

request

response

whitout succes

but on green ( the object for the port) it’s work …

Saw the [EDIT] - does this mean that your problem is resolved?