DataSet issues

  • Thread starter Thread starter Beri Tamas
  • Start date Start date
B

Beri Tamas

Hello,

I have a significant problem with the DataSet (SqlCeDataAdapter) object.
The following piece of code:

Cursor.Current=Cursors.WaitCursor;
SqlCeConnection _con=null;
SqlCeDataAdapter _da=null;
DataSet _ds=null;
try{
_con=new SqlCeConnection("<my data source>");
_con.Open();
_da=new SqlCeDataAdapter("SELECT * FROM Something",_con);
_ds=new DataSet();
_da.Fill(_ds,"dummy");
}
catch{}
finally{
if(_ds!=null){
_ds.Clear();
}
if(_da!=null){
if(_da.SelectCommand!=null)_da.SelectCommand.Dispose();
_da.Dispose();
}
if(_con!=null){
_con.Close();
_con.Dispose();
}
}
System.GC.WaitForPendingFinalizers();
System.GC.Collect();
Cursor.Current=Cursors.Default;

causing an error, a memory leak, the amount of the lost memory depends on
the data in the result set of the select command. The memory will not be
reclaimed, only when I close the whole program itself.

Anyone has an idea?
Thanks,
Tamas Beri
 
Thanks, I've already downloaded and installed it, but the memory leak
problem still occurs every time I'm using the dataset and the fill method.
I've even tried to made a workaround to the Fill method - using DataReader,
but the result was the same :(.
 
shouldn't

System.GC.WaitForPendingFinalizers();
System.GC.Collect();

be

System.GC.Collect();
System.GC.WaitForPendingFinalizers();
System.GC.Collect();

since objects with finalisers require one collection to be added to the
finilisation list and another to finalise?
 
Thanks,

I've tried, without any positive results :(.
It seems this calls to GC goes to /dev/null in a straight line :), the call
has no valuable meaning at all.
Interesting, I've allways thought, that the DataSet implements the
IDisposable interface, but it is not :(, I've realized this when I've tried
the using statement.

Regards,
Tamas Beri
 
The detection was quite simple, I've just started a lot of dialogs in my
program (these dialogs contains a datagrid/dataset, sometimes more then 1),
and I watched the system memory meter built into the iPAQ device.

The framework itself ~2MB after loaded, the SQL Server CE another ~2..2.5MB,
the client program itself ~1MB.

I'm going to try the link You just send as soon as I can.

Thanks, regards:
Tamas Beri
 
1. Is your app actually running out of memory? If not, stop worrying about
it.
2. Calling the GC is very, very, very, very rarely a good idea in the CF.
It doesn't work like the desktop and telling it to collect typicaly has no
effect other than to degrade app perf. Calling Collect does not actually
cause the GC to collect. There are a couple excellent blog entires out
there on how the CF GC works. Google for them.

-Chris
 
1. No, currently not, but I think it's just a matter of time... some dialogs
eat more than 1..2MB-s (these are large lists). Sooner or later, all the
memory will be used.
2. Thanks for the idea, I'm going to look for it.
 
I've finally downloaded the source for the GlobalMemoryStatus interop, the
result is very interesting.
For the first-time run, I've lost ~1MB-s of memory.
Second time, the amount is only ~300K.
3..5: about ~20..30K.
6..8: sometimes the loss is zero, sometimes 5..10K, I do not know, why :)
9 and above: I've actually reclaim 4096 byte for every call.
It seems GC starts to work a lot later than I'm expecting on it, it's very
slow, and, of course, ignore all of my attempts to release the memory
immediatly :).

I'm still going to write a code You mentioned, with the loop, the get the
final delta of the whole process.

Thanks, regards:
Tamas Beri
 
Thanks,

I've actually read this articles, some days or weeks ago. The next thing,
what I'm going to try to resolve this problem, is the multithreading,
mentioned my boss. Maybe if you release/dispose an entire thread, GC will
release the unused memory segs as well. At least, I hope :).

Regards,
Tamas Beri
 
According to this link [1] (Steven Pratschner's "An Overview of the .Net
Compact Framework Garbage Collector"):

A GC collection is initiated when either:

· 750KB of objects have been allocated,

· An application is moved to the background,

· A failure to allocate memory occurs

· An application calls GC.Collect (more on this later).


[1] http://weblogs.asp.net/stevenpr/archive/2004/07/26/197254.aspx

Best regards,
Sergey Bogdanov
 
I've tried. Does not help :(.
The amount of the memory loss is the same.
All that I can do is waiting for Mr. Garbage Collector :).
 
Back
Top