CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2005

    dispose and byte array


    I have the problem that the garbage collector does not delete some byte arrays rapidly... so I get a system memory overflow after a while (I'm working in Windows CE, but this question is also interesting for .net Framework).

    Is there any method to "dispose" a byte array manually without using the GC.Collect() function? I'm setting the byte arrays to NULL if I don't use them anymore... but for my application they stay too long in the memory.

    Any ideas?


  2. #2
    Join Date
    Oct 2005

    Re: dispose and byte array


    I created the following code:

    		int count=1;
    		int counter=100000;
    		private void button1_Click(object sender, System.EventArgs e)
    			test = new byte[counter];
    			MEMORYSTATUS memStatus = new MEMORYSTATUS();
    			GlobalMemoryStatusCE(out memStatus);
    			this.textBox1.Text = memStatus.dwAvailVirtual.ToString();
    			this.textBox2.Text = count.ToString();

    After 27 clicks the system breaks down (OutOfMemoryException). When I put GC.Collect() between test=null and test = new byte[...], I can make util 54 clicks. That means to me that the Garbage Collector doesn't work fine.

    Is there any way to delete the byte array manually without deleting all objects of the Garbage Collector?

  3. #3
    Join Date
    Jan 2002
    Scaro, UK

    Re: dispose and byte array

    Try GC.GetTotalMemory(true) - this is better at forcing a complete garbage collect than GC.Collect().

    However, after 54 clicks you are using 10Mb for the array - rather a lot for a compact device I would have thought anyway.

    At any rate it's unlikely any application would use memory the way that you are : it's far more likely that allocations will be done once.

    The alternative is to use a C++ dll to do your memory allocations/deallocations/access for large buffers.

    Last edited by darwen; June 6th, 2006 at 04:17 PM.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.