Objects "Eating" up memory

Z

Zahid

Hi,

Im writing and testing an app (written in VB.Net) on my
PocketPC which dynamically creates buttons and places
them on tabpages in a tabcontrol. The buttons are custom
created buttons. In one on the tabpages certain buttons,
if clicked, will refresh the tabpage they are contained
in by loading a new set of buttons.

On inspecting this further i have found that this is
eating away my memory. Why? If a button loads a new set
of buttons then in my code the first line i have placed
is "frm1.TabControl1.Tabpages.Clear()" which forces the
tabpage to be deleted/disposed so that new fresh tabpages
are created for the new set of buttons.

When I call the line "frm1.TabControl1.Tabpages.Clear()"
does this also delete my custom designed buttons also? Or
do they still exist - hence why the memory is being eaten
into?

All advice and help is GREATLY appreciated.
Thanks in advance.
 
Z

Zahid

Thanks,

Do you mean create a destructor for my custom buttons and
call the Dispose method from inside it?

How do i remove the buttons from the forms controls
collection? Sorry but im a lil new to VB.Net.

Thanks in advance,
Zahid.
 
A

Alex Feinman [MVP]

Form.Controls.Remove(myButton)
myButton.Dispose()

The reason is that in NetCF there is an inaccessible directly reference to
every control in a global private static array - member of the Control
class, which prevents GC from collecting it
 
Z

Zahid

Hi,

I tried your code but the memory is still being eaten
away sadly. Is there anything else I can try?

Thanks in advance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top