Watch instances of objects

  • Thread starter Thread starter Benjamin Lukner
  • Start date Start date
B

Benjamin Lukner

Hi!

I've got the problem that the Pocket PC memory is full after 350 logouts
and logins with my software. There seems to be a tiny memory leak caused
by objects/instances that don't dispose on logout.

I need something to watch all the loaded instances, because I don't know
any other way to find the error.

(I'm sure this question was asked previously, but I don't know what to
search for, sorry).

Kind regards,

Benjamin Lukner
 
Have you installed the latest SP (at this moment SP3 [1])? There are
some issues concerning memory leaks fixed by the SP2 [2]:

- Memory leak in the NumericUpDown, DomainUpDown, ComboBox and TextBox
controls
- conversion of 0.0F to a string and results in a memory leak

[1]
http://www.microsoft.com/downloads/...da-fc5d-41cc-ac04-7bb50a134556&displaylang=en
[2]
http://www.microsoft.com/downloads/...11-194b-4c00-b445-f92bec03032f&displaylang=en

For performance statistics see this article, there are lots of counters:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetcomp/html/netcfperf.asp


Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com
 
If you are looking for something that shows you a graph (or equivalent) of
your live instances, then no, there isn't something like that for the
Compact Framework that I am aware of. There are plenty of tools that do that
kind of thing for the desktop though. I recall having to use one of them in
the distant past with the desktop version of my CF code (yet another reason
for having your code run on both platforms but I digress).

Now, if you are looking for generic guidance for dealing with memory issues
with the CF, I suggest you look at my memory FAQ:
http://www.danielmoth.com/Blog/2005/01/memory-problems-faq.html

Cheers
Daniel
 
Daniel Moth wrote:

Hi Daniel and Sergey,

Thanks for your quick answers. Unfortunately I had the flu, that's why I
answer only now.
If you are looking for something that shows you a graph (or equivalent)
of your live instances, then no, there isn't something like that for the
Compact Framework that I am aware of. There are plenty of tools that do
that kind of thing for the desktop though. I recall having to use one of
them in the distant past with the desktop version of my CF code (yet
another reason for having your code run on both platforms but I digress).

I'm looking for something like the quick watch. Something that shows a
list of ALL loaded objects of my software (when debugging via ActiveSync).

My software almost runs on both platforms simultaneously (there are only
2 lines of code that are vital for XP I can't compile in CF).

I've added

GC.Collect()
GC.GetTotalMemory(True)
GC.WaitForPendingFinalizers()

to my code. Also a routine that restarts the software every 10 seconds
(only "internal" restart). The memory usage under XP stays the same.
Under Win.CE the usage increases by ca. 80kb on every restart.

So I have to check all the CE specific API calls, I think. I'll upgrade
from SP2 to SP3, too. Though I'm only using drawing.bitmap and
drawing.graphics. I'm not using any standard controls...

Kind regards,

Benjamin Lukner
 
Benjamin said:
I've added

GC.Collect()
GC.GetTotalMemory(True)
GC.WaitForPendingFinalizers()

to my code. Also a routine that restarts the software every 10 seconds
(only "internal" restart). The memory usage under XP stays the same.
Under Win.CE the usage increases by ca. 80kb on every restart.

It took me a long time, but finally I've found the problem.

Create a new Windows or PPC Application and put a button on it.
Then insert the following code:


Private Class cControl

Inherits Control

Protected Overrides Sub OnPaintBackground _
(ByVal pevent As System.Windows.Forms.PaintEventArgs)
'DeActivate
End Sub

Protected Overrides Sub OnPaint _
(ByVal e As System.Windows.Forms.PaintEventArgs)
e.Graphics.FillRectangle _
(New System.Drawing.SolidBrush(System.Drawing.Color.Gold) _
, 0, 0, 96, 24)
End Sub

Protected Overrides Sub Finalize()
MsgBox("Finalized!")
MyBase.Finalize()
End Sub

End Class


Private WithEvents oControl As cControl

Private Sub Button1_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs _
) Handles Button1.Click

If oControl Is Nothing Then
oControl = New cControl
oControl.Location = New System.Drawing.Point(8, 8)
oControl.Size = New System.Drawing.Size(96, 24)
Me.Controls.Add(oControl)
Else
Me.Controls.Remove(oControl)
' Insert Dispose here!
oControl = Nothing
End If

End Sub


Controls that have been removed from a form DON'T dispose automatically!
The MessageBox(es) won't pop up before the form is closed.
It is absolutely neccessary to call oControl.Dispose before setting it
to nothing.

Can anyone explain why?

Kind regards,

Benjamin Lukner
 
Back
Top