I made a program thats read xml files from a usb stick and collect specific data from it.
But after collecting the data the BINARY_BLOB_HEAD keep getting bigger and after each run until I run out of memory.
Does anyone know how I can solve this problem?
Started:
GC: 3msec 34536 bytes used, 29844 bytes available
Type 0F (STRING ): 1152 bytes
Type 11 (CLASS ): 4008 bytes
Type 12 (VALUETYPE ): 72 bytes
Type 13 (SZARRAY ): 2472 bytes
Type 15 (FREEBLOCK ): 29844 bytes
Type 16 (CACHEDBLOCK ): 324 bytes
Type 17 (ASSEMBLY ): 13404 bytes
Type 18 (WEAKCLASS ): 48 bytes
Type 19 (REFLECTION ): 24 bytes
Type 1B (DELEGATE_HEAD ): 468 bytes
Type 1C (DELEGATELIST_HEAD ): 48 bytes
Type 1D (OBJECT_TO_EVENT ): 96 bytes
Type 1E (BINARY_BLOB_HEAD ): 8304 bytes
Type 1F (THREAD ): 1536 bytes
Type 20 (SUBTHREAD ): 192 bytes
Type 21 (STACK_FRAME ): 1020 bytes
Type 27 (FINALIZER_HEAD ): 96 bytes
Type 31 (IO_PORT ): 72 bytes
Type 34 (APPDOMAIN_HEAD ): 72 bytes
Type 36 (APPDOMAIN_ASSEMBLY ): 1128 bytes
Ended:
C: 3msec 53976 bytes used, 10404 bytes available
Type 0F (STRING ): 2088 bytes
Type 11 (CLASS ): 5616 bytes
Type 12 (VALUETYPE ): 72 bytes
Type 13 (SZARRAY ): 2472 bytes
Type 15 (FREEBLOCK ): 10404 bytes
Type 17 (ASSEMBLY ): 13404 bytes
Type 18 (WEAKCLASS ): 48 bytes
Type 19 (REFLECTION ): 24 bytes
Type 1B (DELEGATE_HEAD ): 468 bytes
Type 1C (DELEGATELIST_HEAD ): 48 bytes
Type 1D (OBJECT_TO_EVENT ): 96 bytes
Type 1E (BINARY_BLOB_HEAD ): 25296 bytes
Type 1F (THREAD ): 1536 bytes
Type 20 (SUBTHREAD ): 192 bytes
Type 21 (STACK_FRAME ): 1248 bytes
Type 27 (FINALIZER_HEAD ): 96 bytes
Type 31 (IO_PORT ): 72 bytes
Type 34 (APPDOMAIN_HEAD ): 72 bytes
Type 36 (APPDOMAIN_ASSEMBLY ): 1128 bytes
Failed allocation for 89 blocks, 1068 bytes
#### Exception System.OutOfMemoryException - CLR_E_OUT_OF_MEMORY (3) ####
#### Message:
#### Microsoft.SPOT.IO.NativeFileStream::.ctor [IP: 0000] ####
#### System.IO.FileStream::.ctor [IP: 00fd] ####
#### System.IO.FileStream::.ctor [IP: 0010] ####
#### Test.Program::task1 [IP: 0096] ####
A first chance exception of type ‘System.OutOfMemoryException’ occurred in Microsoft.SPOT.IO.dll
A first chance exception of type ‘System.OutOfMemoryException’ occurred in System.IO.dll
An unhandled exception of type ‘System.OutOfMemoryException’ occurred in System.IO.dll
Code:
using System;
using System.Text;
using System.IO;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.IO;
using GHIElectronics.NETMF.IO;
using GHIElectronics.NETMF.USBHost;
using System.Xml;
namespace Test
{
class Program
{
// Hold a static reference in case the GC kicks in and disposes it
// automatically, note that we only support one in this example!
static PersistentStorage ps;
static string rootDirectory;
static bool systemready;
static int hour;
static int minute;
static string str;
static string str1;
static string str2;
static FileStream stream;
public static void task1()
{
hour =0;
minute = 0; ;
str1="";
str2="";
while (true)
{
Debug.Print("Task 1 is up");
minute++;
if (minute == 60)
{
minute=0;
hour++;
}
if (hour == 24)
{
hour = 0;
minute = 0;
}
str1 = @ "\sundata" + hour.ToString() + ".xml";
str2 = "Pair" + minute.ToString();
if (systemready)
{
stream = new FileStream(rootDirectory + str1, FileMode.Open);
XmlReader reader = XmlReader.Create(stream);
//read through all the nodes
while (reader.Read())
{
//the headlines we want are in the item nodes
if (reader.NodeType == XmlNodeType.Element)
{
if (reader.Name == str2)
{
str="";
str = reader.GetAttribute(0);
Debug.Print(str);
str = reader.GetAttribute(1);
Debug.Print(str);
str = reader.GetAttribute(2);
Debug.Print(str);
str = reader.GetAttribute(3);
Debug.Print(str);
}
}
}
stream.Close();
stream.Dispose();
reader.Close();
reader.Dispose();
}
Debug.GC(true);
Thread.Sleep(100);
Debug.Print("Task 1 is down");
}
}
public static void Main()
{
Debug.Print("this is main");
Thread task1Handler = new Thread(task1);
task1Handler.Start();
// Subscribe to RemovableMedia events
RemovableMedia.Insert += RemovableMedia_Insert;
RemovableMedia.Eject += RemovableMedia_Eject;
// Subscribe to USB events
USBHostController.DeviceConnectedEvent += DeviceConnectedEvent;
// Sleep forever
Thread.Sleep(Timeout.Infinite);
}
static void DeviceConnectedEvent(USBH_Device device)
{
if (device.TYPE == USBH_DeviceType.MassStorage)
{
Debug.Print("USB Mass Storage detected...");
ps = new PersistentStorage(device);
ps.MountFileSystem();
}
}
static void RemovableMedia_Insert(object sender, MediaEventArgs e)
{
if (e.Volume.IsFormatted)
{
rootDirectory = VolumeInfo.GetVolumes()[0].RootDirectory;
systemready = true;
}
else
{
Debug.Print("Storage is not formatted. Format on PC with FAT32/FAT16 first.");
}
}
static void RemovableMedia_Eject(object sender, MediaEventArgs e)
{
Debug.Print("Storage \"" + e.Volume.RootDirectory +
"\" is ejected.");
}
}
}