R
Roberto Rocco
Hello all,
We've got the following severe and very strange problem:
We open a modal form with ShowDialog() containing nothing but a PictureBox with an image of approx. 500 kB.
The code looks like this:
FormTest frm = new FormTest();
frm.ShowDialog();
Then we manually close the form with this.close (inside the form).
After the form has been closed we always log the physical memory on the device.
Then we show the form again, close it again, and so on...
What we notice is that the physical memory decreases each time the form is shown and that memory is not released after the form has been closed.
This happens a couple of times since finally an out of memory error occurs!
So the garbage collector obviously did not manage to clear the resources.
If we make a Dispose() call instead after the form has been closed, then the memory gets freed from time to time and it never comes to a point where an out of memory error occurs.
So this way the garbage collector obiously manages to free the resources.
Now what does this mean??
According to MSDN it says: "When a form is closed, all resources created within the object are closed and the form is disposed"
So from my understanding that means that closing a form implicitly calls Dispose() on the form, or does it not??
If not - and that's what we experience - then one would have to make a Dispose() call every time a form has been closed, as so:
FormTest frm = new FormTest();
frm.ShowDialog();
frm.Dispose();
Or, alternatively use the using-statement (but due to a bug in CF 1.0 you have to add IDisposable to the form definition manually!).
Is this really the correct behaviour?
Is the caller of a form really required to call Dispose() manually?
If of any interest I can supply a little Test Application that proofs this behaviour.
Many thanks in advance for every enlightment on this.
Best regards,
Roberto Rocco.
We've got the following severe and very strange problem:
We open a modal form with ShowDialog() containing nothing but a PictureBox with an image of approx. 500 kB.
The code looks like this:
FormTest frm = new FormTest();
frm.ShowDialog();
Then we manually close the form with this.close (inside the form).
After the form has been closed we always log the physical memory on the device.
Then we show the form again, close it again, and so on...
What we notice is that the physical memory decreases each time the form is shown and that memory is not released after the form has been closed.
This happens a couple of times since finally an out of memory error occurs!
So the garbage collector obviously did not manage to clear the resources.
If we make a Dispose() call instead after the form has been closed, then the memory gets freed from time to time and it never comes to a point where an out of memory error occurs.
So this way the garbage collector obiously manages to free the resources.
Now what does this mean??
According to MSDN it says: "When a form is closed, all resources created within the object are closed and the form is disposed"
So from my understanding that means that closing a form implicitly calls Dispose() on the form, or does it not??
If not - and that's what we experience - then one would have to make a Dispose() call every time a form has been closed, as so:
FormTest frm = new FormTest();
frm.ShowDialog();
frm.Dispose();
Or, alternatively use the using-statement (but due to a bug in CF 1.0 you have to add IDisposable to the form definition manually!).
Is this really the correct behaviour?
Is the caller of a form really required to call Dispose() manually?
If of any interest I can supply a little Test Application that proofs this behaviour.
Many thanks in advance for every enlightment on this.
Best regards,
Roberto Rocco.