.NET CF slowly leaking memory?

A

awaken77

My app calling async web service in a loop, cancelling the request via
handle.Abort() if timeout is expired.

I started continious test in environment where WebService always fails
(call to WS never returned to client and always cause to Abort() )

After 18000 polling cycles, overall memory consumption increased from
15,13Mb to 15,59Mb. During some little period of time it seems to be
constant, but is slowly grows.
Is it a leak related to async WS call mechanism?

Application also does some work with MSSQL CE but I call Dispose() for
Command object after each usage for sure.
I do not create and destroy forms many times (there is only one form
with controls, created at startup), so I don't see other possible
sources for leaking.

I have some opinion why does it work this way. WebService proxy using
internally a thread in BeginXXX method. This thread creates HTTP
connection via underlying socket API (unmanaged). When unmanaged call
is invoked, resources allocated in this thread are "pinned" by GC to
particular memory block. So this block never released before thread
runs to completion.
Each new polling cycle, pending async request object is not destroyed,
but new one created. So these hidden threads grow in number, as I poll
web service with low interval (once per second), but thread can hang on
connection for a long timeout.
Am I right?

p.s. my environment:
..NET CF SP3
Windows Mobile 2003 SE
ARM emulator (from VS2005), or Axim X30
 
A

awaken77

Thanks!
But I didn't see described kind of error "Not enough storage is
available to complete this operation"
memory just slowly growth and application seems to response slower. On
ARM(Axim) it occasionally stopped responding at all after working 3
days, and I terminated it from task list.


I use DataReader object in scenario like this:
it seems to be memory-safe

public void GetData(SomeObj[] array)
{
lock(_db) // DB object
{
SqlCeCommand cmd = _db.Connection.CreateCommand();
try
{
cmd.CommandText = "SELECT blah-blah-blah"
SqlCeDataReader rd = cmd.ExecuteReader();
using(rd)
{
while(rd.Read())
{
// populate collection from Recordset
}
rd.Close(); // possible not necessary
}
}
catch(SQLCEException ex)
{
// error handling
}
finally
{
cmd.Dispose();
}
}
}
 
C

Chris Tacke, eMVP

So you never get an error about being out of memory? Then don't worry about
it - it's likely garbage that will get collected on a GC collection cycle.

--
Chris Tacke
Co-founder
OpenNETCF.org
Are you using the SDF? Let's do a case study.
Email us at d c s @ o p e n n e t c f . c o m
http://www.opennetcf.org/donate
 

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