Thursday, November 26, 2009

SQL CE Takes too much Memory

This is a bast form the past, I was thinking about how to promote my new blog so I signed into http://www.vbforums.com to answer a few questions, and I found this posting, something I figured out and posted about 5 years ago.  This was two posts, the first one describing my problem and the second one gives the solution.

----- (POST #1)

I have an MC 1000. At first I thought it was perfect, ultra low cost, and no extra features that were never used. At first they run perfectly, but after you insert a few hundred records into its CE Database it starts running slower and slower until it is almost unusable. I have the users reboot the device and it runs fine again for a while but does the same thing again. All my code is doing is adding records to the SQL CE DB.

Anyone have similar problems? I am thinking of switching over to a XML file instead of SQL CE.

I have converted as much storage memory into program memory and it has helped, but only for a while.

----- (POST #2)

I came across the following MS Article while researching this problem:

http://support.microsoft.com/?kbid=842191


It mentions:

Q17: Does setting my ADO Recordset to 'nothing' reclaim any memory?

A17: Generally, the answer is "yes." However, Microsoft recommds that all your applications use set rs=nothing and set cn=nothing when you are finished using them. Database engines can take a fair amount of memory, and it is best not to leak memory.

Usually, Microsoft Visual Basic eventually releases the memory. However, there have been some cases where the memory is not released quickly enough and you can run out of memory on the device, especially if you have a particularly bad memory leak.

Made me think: am I setting all my objects to nothing? I went through my code and found that although I was setting all my Connections = Nothing I wasn't setting the SqlCeCommand Objects to nothing when I was done with them. I added a few cmd = Nothing lines and now my App runs Faster then ever and doesn't seem to be stopping for anything.

Whoo!




No comments:

Post a Comment