Causes of Memory leaks in .NET CF Apps?

G

Guest

Hi

Im close to completing (so i think i am) my COMPLEX .Net CF app written in VB.NET

I need to know how to examine my app to find bottleneck because I think my app is LEAKING memory. Are there any tools

Im using ArrayLists, 20 different custom classes (with simple data members like ints, chars, etc), writing to files, an adapted version of the picture button from gotdotnet, SQLServer CE, and reusing 2 Threads from the ThreadPool.
So the memory could be leaking from anywhere. Any areas you suggest I inspect

Thanks Guys.
 
C

Chris Tacke, eMVP

Managed apps by design shouldn't be able to leak anything. P/Invoking
memory allocations can cause leaks, but otherwise it's not really possible.
What makes you think you're got leaks?

-Chris


James Anderson said:
Hi,

Im close to completing (so i think i am) my COMPLEX .Net CF app written in VB.NET.

I need to know how to examine my app to find bottleneck because I think my
app is LEAKING memory. Are there any tools?
Im using ArrayLists, 20 different custom classes (with simple data members
like ints, chars, etc), writing to files, an adapted version of the picture
button from gotdotnet, SQLServer CE, and reusing 2 Threads from the
ThreadPool.
 
G

Guest

Thanks for the swift response

I stated up my app. Then using the memory tab under system settings looked at the memory allocation. To my surprise, the In Use memory was increasing and continues to do so for about 30 secs. It went up about 1.2MB

Then I started using my app (which uses UDP comms) and after a minute went to examine the memory and noticed that the InUse memory was up my 580KB.

Im re-using Threads from the thread pool, maybe im using them incorrectly? When I power off my device an power on again the UDPClient loses connection. So what I do is I close the 2 threads for UDP Comms (Send and Listen Threads) and restart them - using the ThreadPool. Is this bad by design

Any Ideas

Thanks a great deal.
 
A

Alex Yakhnin [MVP]

Then I started using my app (which uses UDP comms) and after a minute went
to examine the memory and noticed that the InUse memory was up my 580KB.

Does the memory continue to grow?

--
Alex Yakhnin .NET CF MVP
www.intelliprog.com | www.opennetcf.org

James Anderson said:
Thanks for the swift response.

I stated up my app. Then using the memory tab under system settings looked
at the memory allocation. To my surprise, the In Use memory was increasing
and continues to do so for about 30 secs. It went up about 1.2MB.
Then I started using my app (which uses UDP comms) and after a minute went
to examine the memory and noticed that the InUse memory was up my 580KB.
Im re-using Threads from the thread pool, maybe im using them incorrectly?
When I power off my device an power on again the UDPClient loses connection.
So what I do is I close the 2 threads for UDP Comms (Send and Listen
Threads) and restart them - using the ThreadPool. Is this bad by design?
 
G

Guest

Hi Alex

Well, there comes a point whilst observing the memory that it stops increasing. I think it may be the ThreadPool, its behaving a little strange. Sometimes the threads get recalled quickly whilst on other occasions its takes a while for them to be recalled. Why is this

Also, I understand (maybe incorrect) that when an object gets created (custom class object) in a procedure and the procedure completes them the object is implicitly destroyed by the GC. Is that correct? or do I still need to call
"Object = Nothing" - In some places I call "Object = Nothing" and in others i dont.

Thanks a great deal

James.
 
C

Chris Tacke, eMVP

Sounds like you're fine. The GC collects at defined memory loads, so if you
don't hit them, it's not going to waste time running around cleaning up.
This helps app performance. I'd only worry if you start seeing out of
memory exceptions or some such.

Your thread handling seems reasonable too. Not sure how else you would
handle it.

--
Chris Tacke, eMVP
Co-Founder and Advisory Board Member
www.OpenNETCF.org
---
---
Principal Partner
OpenNETCF Consulting
www.OpenNETCF.com



James Anderson said:
Thanks for the swift response.

I stated up my app. Then using the memory tab under system settings looked
at the memory allocation. To my surprise, the In Use memory was increasing
and continues to do so for about 30 secs. It went up about 1.2MB.
Then I started using my app (which uses UDP comms) and after a minute went
to examine the memory and noticed that the InUse memory was up my 580KB.
Im re-using Threads from the thread pool, maybe im using them incorrectly?
When I power off my device an power on again the UDPClient loses connection.
So what I do is I close the 2 threads for UDP Comms (Send and Listen
Threads) and restart them - using the ThreadPool. Is this bad by design?
 
A

Alex Yakhnin [MVP]

Also, I understand (maybe incorrect) that when an object gets created
(custom class object) in a procedure and the procedure completes them the
object is implicitly destroyed by the GC. Is that correct? or do I still
need to call
"Object = Nothing" - In some places I call "Object = Nothing" and in
others i dont.

You don't need to do it in order for object to be GC'ed, but you should
remember that objects WILL NOT be destroyed immedietly after going out of
scope. The GC lives by its own rules and would start collecting unneeded
stuff whenever the memory/time threshholds are reached.

HTH... Alex

--
Alex Yakhnin .NET CF MVP
www.intelliprog.com | www.opennetcf.org

James Anderson said:
Hi Alex,

Well, there comes a point whilst observing the memory that it stops
increasing. I think it may be the ThreadPool, its behaving a little
strange. Sometimes the threads get recalled quickly whilst on other
occasions its takes a while for them to be recalled. Why is this?
Also, I understand (maybe incorrect) that when an object gets created
(custom class object) in a procedure and the procedure completes them the
object is implicitly destroyed by the GC. Is that correct? or do I still
need to call
 

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