-
June 6th, 2006, 08:56 AM
#1
dispose and byte array
Hello,
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?
Thanks!
-
June 6th, 2006, 01:54 PM
#2
Re: dispose and byte array
Hi...
I created the following code:
Code:
int count=1;
int counter=100000;
private void button1_Click(object sender, System.EventArgs e)
{
test=null;
test = new byte[counter];
MEMORYSTATUS memStatus = new MEMORYSTATUS();
GlobalMemoryStatusCE(out memStatus);
this.textBox1.Text = memStatus.dwAvailVirtual.ToString();
this.textBox2.Text = count.ToString();
count++;
counter+=200000;
}
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?
-
June 6th, 2006, 04:14 PM
#3
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.
Darwen.
Last edited by darwen; June 6th, 2006 at 04:17 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|