I have been battling with a memory leak that causes my desktop application to crash from time to time - usually when changing from one window to another in OSX.
I have stopped using self.close in windows and using self.hide instead. That seems to have helped.
Is there a definitive write-up on best practice? If not, I would appreciate any helpful comments forum members feel worth sharing.
Topics might include when and where to close database access, better solutions to closing windows…
Thanks in advance
i have a debug menu , i open a window with listbox and label and show some useful info.
- have a look at WeakAddressOf and WeakRef.
if this data looks good than perhaps the leak is somewhere else.
Sub Open() Handles Open
Var lastObjectIndex As Integer = Runtime.ObjectCount - 1
Var objectRefs As Integer = 0
For i As Integer = 0 To lastObjectIndex
Listbox1.CellValueAt(ListBox1.LastAddedRowIndex, 1) = Runtime.ObjectClass(i)
Listbox1.CellValueAt(ListBox1.LastAddedRowIndex, 2) = Runtime.ObjectRefs(i).ToString
objectRefs = objectRefs + Runtime.ObjectRefs(i)
Label1.Value = Str(Runtime.MemoryUsed)+ " bytes total amount of memory used by the allocated objects " +objectRefs.ToString
I have one article planned for memory leaks. In short:
- Select Leaks instead of TimeProfiler.
- Let Instruments run for a while.
- Now dig into the memory leaks.
Thanks for your article. It helped me to work out a couple of things I have been doing wrong.
Now I just have to refactor the code…