Regrettably you have discovered a bug in all versions of .NETCF for
ARM-compatible devices. We are still investigating the problem and
potential solutions. This bug can cause a small number of memory objects to
remain allocated even when they are no longer referenced. In our testing,
no more than 6 objects can be "leaked" in this way and typically the number
is much smaller. Since only a limited number of objects can be affected, in
most cases the impact is not noticeable, but because the objects allocated
by your application are so large, leaking even a few of them is more
serious.
Since this bug only exists on ARM-compatible devices, it is possible to
confirm that you are experiencing this particular problem by running your
application in the PocketPC emulator supplied with Visual Studio. If memory
is leaked on your device but not the emulator, then it is possible you are
experiencing this problem.
In more technical detail, the bug is caused by .NETCF erroneously believing
that an uninitialized block of memory outside of your application's control
may contain object references. If by chance the data within this
uninitialized block points to a valid object, that object (and any objects
it references) will be kept alive indefinitely. The larger an object is,
the greater the likelihood that one of these semi-random uninitialized
values will fall within the bounds of the object. Therefore a very large
object (such as the ones your application is allocating) is more likely to
be leaked than a small object.
At this time we know of no way to completely avoid this problem or predict
exactly which objects will be leaked. In your particular case, the impact
of the bug could be lessened by allocating smaller objects -- the same
number of objects will likely be leaked but the total amount of memory
consumed will be less.
We are working on a solution and we will notify you when it is released.
Thank you for the report.
--------------------
From: "Arsa" <
[email protected]>
Subject: Re: Memory problem with byte[]
Date: Fri, 16 Jan 2004 21:04:41 +0100
Hi Paul and Group,
Here is a sample application in attachement.
It's a simple form with a button. First Click is ok but the second crashes
(I have small memory on a Dell Aximx5 32M, and CompactFramework SP2). I uses
a function called shouMem to desplay the memory using GC.ShowMemoryUse.
Please let me know how it behaves.
Am I doing something wrong? is there any work around?
Thanks in advance.
Arsa
"Paul G. Tobey [eMVP]" <ptobey_no_spam@instrument_no_spam.com> a écrit dans
le message de news:
[email protected]...
You should probably post a very simple example that fails with the Out Of
Memory exception and let us know what version of the framework you are
using. It sounds like a bug in the framework, just based on your
description.
Paul T.
Thanks for the reply.
I know the GC will not run Immediatly. But what is annoying is that I am
using 2 big bytes arrays in my function. Between two calls of that
function
the memory is not always freed, even if I manually run the GC.Collect().
On
the next calls, the memory used is growing which somtimes causes an
"OutOfMemoryException".
By the way when I send my application background and bring it back (That
causes GC to run), memory is freed.
What is the right way to force the GC to run correctly? GC.Collect() alone
doesn't seem to clear memory.
Or is there a better work around to properly clear the memory used by
bytes
array "byte[]" without using GC?
Thanks in advance,
Arsa
"Alex Feinman [MVP]" <
[email protected]> a écrit dans le message
de You can try calling GC.Collect, but in general the memory will be freed
when
the next allocation request cannot be satisfied, or the system becomes
idle
Hi,
When i set a byte array to null the memory doesn't seem to be freed.
Here
is
sample code where the problem occurs:
private void testBytesArray()
{
byte[] BA1 = null;
try
{
BA1 = new byte[2000000];
for (int i = 0; i<2000; i++)
{
BA1
= (byte)i;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
BA1 = null;
}
}
The BA1 takes 2Mb of memory, after calling BA1 = null the memory used
remains 2Mb and when calling a second time BA1 = new
byte[2000000]
it
jumps
to 4Mb. Is it a know issue in the compact framework with the GC or
somthing
missing in my code? Any work around possible to release the memory?
Thanks,
Arsa
This posting is provided "AS IS" with no warranties, and confers no rights.