Re initialize the size of array but face OutOfmemoryException

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • macneed

    #1

    Re initialize the size of array but face OutOfmemoryException

    i wrote a program that have a large size array, but the size is change often
    (about 3 -4 mins)

    the program like that:

    public class MemoryArray
    {
    public float[,,] MM;

    public MemoryArray(int Size)
    {
    MM = new float[Size, 10000, 10000];
    }
    }

    static void Main(string[] args)
    {
    int[] SizeArray = { 100, 200, 300, 400 };
    MemoryArray MA = new MemoryArray(1);
    int i=0;

    while (true)
    {
    MA = null; // I try to use it to release memory
    GC.Collect();

    MA = new MemoryArray(Siz eArray[i++%4];
  • macneed

    #2
    Re: Re initialize the size of array but face OutOfmemoryExce ption

    MISS REPLY
    I WILL OPEN A NEW THREAD
    PLEASE SKIP THIS
    THANKS

    "macneed" <macneed@yahoo. com.hk¼¶¼g©ó¶l¥ ó·s»D:48d235ec@ 127.0.0.1...
    >i wrote a program that have a large size array, but the size is change
    >often (about 3 -4 mins)
    >
    the program like that:
    >
    public class MemoryArray
    {
    public float[,,] MM;
    >
    public MemoryArray(int Size)
    {
    MM = new float[Size, 10000, 10000];
    }
    }
    >
    static void Main(string[] args)
    {
    int[] SizeArray = { 100, 200, 300, 400 };
    MemoryArray MA = new MemoryArray(1);
    int i=0;
    >
    while (true)
    {
    MA = null; // I try to use it to release memory
    GC.Collect();
    >
    MA = new MemoryArray(Siz eArray[i++%4];
    .
    .
    .
    >
    }
    }
    >
    >
    But the program seems can't release memory,
    it alway break at below line after running a period of time
    MA = new MemoryArray(Siz eArray[i++%4];
    and return a outofmemoryexce ption
    >
    how can i release a array allocated memory and reset the size of it?
    >
    THANKS
    >

    Comment

    Working...