index > SQL Server Everywhere Edition > SqlCe Memory issue

SqlCe Memory issue

Hi all, I am querying an SqlCe Database on my PDA and noticed that the device is slowly running out of memory every time I execute a query. I am using the following code:

public  SqlCeDataReader ExecuteReader(string command, params SqlCeParameter[] commandParameters)
        {
            SqlCeDataReader reader = null;
            SqlCeCommand c = new SqlCeCommand(command, cn);
            try
            {
                for (int i = 0; i < commandParameters.Length; i++)
                    c.Parameters.Add(commandParametersIdea);
                reader = c.ExecuteReader();
            }
            catch
            {
                // Release resources
                c.Parameters.Clear();
                reader.Close();
                throw;
            }
            c.Parameters.Clear();
            return reader;
        }

This method is a part of my 'SqlCeHelper' class that I have written.

I noticed that when I reach the line reader = c.ExecuteReader() , the memory of my device decreases by about 1%. The reader is returned to a class which makes use of it and then disposes of it by calling reader.Close(); The connection to the database is also closed properly at some point, but memory never gets released. Memory gets only released when the application terminates.

I am wondering if I am doing something wrong by not disposing of some resources. Please help!

(Also tried GC.Collect() , didn't help!)

Cheers.




Miroslav
Miroslav_shrek
Remember to also call Dispose on the SqlCeDataReader. This will effectively dispose all the managed and unmanaged resources and you should do this at the earliest.


João Paulo Figueira (Device Application Development MVP)
João Paulo Figueira

Hi,

first of all - thanks for your reply!

I have called reader.Dispose() and nothing really improved. In the class that uses the reader returned by the above method, the code is as follows:

IDataReader reader = null;

try

{

reader = _dbHelper.ExecuteReader("SELECT * FROM MeasurementInstance");

while (reader.Read())

{

if (reader != null && !reader.IsClosed)

{

...get relevant data from the reader and store it...

}

}

reader.Close();

reader.Dispose();

Nothing seems to improve. Just as a side question - when I create parameters for the SqlCeCommand, for example:

SqlCeParameter taskParam = new SqlCeParameter("@TaskId", SqlDbType.BigInt);

taskParam.Value = taskID;

Is there a need to call dispose on the parameters at some point? Any other ideas why my memory might be getting wasted?

Cheers,




Miroslav
Miroslav_shrek

Are you actually running out of memory... getting a memory error?

Or are you just worrying about a memory leak?

I've noticed that with the PDA that memory is claimed and is not returned so quickly. However when it needs it the memory is returned. I have found no command such as Dispose... and dumping the garbage collection seems to not do much, if anything at all. However as stated I would still use the good programming practice of always dispose objects that offer 'dispose' as an option.

I've got an extensive application running on a PDA out in the field. The nurses often express complaints over slowness. I have them do a soft-reset periodically that seems to clean up things.

I believe that the memory leaks are due to the .NET system, or SQL Ce. I don't think we can do much about them, aside from a Soft-Reset... or a microsoft reboot...LOL

I hope that in the new version of SqlCe that these problems will not persist.




-Robert
robertkjr3d
Hi,

Yeah I was really suspicious of something like this... I have really tried everything, but the only way to realease the resources is to either kill the application or do a soft reset. There are really no particular problems with the memory issues, except that it gets slower and slower. I really hope this will get fixed at some point!

Thanks everyone!



Miroslav
Miroslav_shrek
reply 5

You can use google to search for other answers

 

More Articles

• Using Merge Replication, Parameterized Filters
• ANYONE CAN HELP ME PLEASE?
• Should I use Merge Replication ahead 3rd party synch tool
• installing sql server mobile in an hp ipaq rx1955
• Can I use SQL_Mobile as PC desktop server or PC local cache serve...
• Inner workings of RDA
• connecting to sql server from mobile device
• Using RDA to insert an image type from SQL Mobile to SS2005
• Behavior difference between SQL Mobile Providers SSCE20.DLL and S...
• SQL Server Mobile Merge Replication walkthrough, cant find the .N...
Bookmark and Share
Welcome to Bokebb   New Update  
 

New Articles

• Client-side programming patterns/idioms
• Problems adding MS access datasource in
• What is SQL Everywhere?
• How to create a SQL ev DB?
• Remote synchronise from PDA to SQL Serve
• Connecting to SQL Mobile within VS-2005
• RDA pull - from a temporary table
• Relational Data and RDA
• SQL Mobile Embedded XP support?
• OutOfMemoryException with SQL Server Mob
• Sync of binary columns in SQL 2005 EV an
• SQL Mobile Server Tools install on SQL 2
• Determining if a SqlCeDataReader has ret
• Can't Insert Binary Data Into Sql Mobile
• rda localconnection

Hot Articles

• SQL Mobile query hangs PPC 2003 device
• Open SqlCeConnection from an ASP.NET Web
• SQL Mobile Embedded XP support?
• sql server mobile 2005 and emulated stor
• Connecting Database Engine (SQl server 2
• Creating and deploying sql mobile databa
• Obtain sqlceresultset table schema with
• Maximum length sql statement that can be
• Is IIS always required for replication?
• How does this, ResetDbType(), work
• Question on synching through RDA using p
• SqlCeEngine Verify/Repair methods
• SQL Server Mobile Bug?
• Rapi SecurityPolicy on Windows Mobile 5
• create tables and insert data in sql ser

Recommend Articles

• Debuggin on PDA
• sql mobile question
• I am not sure whether I can use sql mobi
• rda.push error
• Why I can't connect sql server 2000 with
• BLOB Merge Replication
• Synchronisation using web service for PD
• Help setting up replication on remote IIS
• SQL Server Mobile - Reset Increment
• Delete Update Behavior of the SSEv Engine
• SQL Mobile - Locale Not supported
• Can't Insert Binary Data Into Sql Mobile
• Wireless synchronisation
• Convert SQLExpress db to Sql Anywhere
• SQL Everywhere Remote