Red Gate forums :: View topic - Memory Issues with large syncs
Return to www.red-gate.com RSS Feed Available

Search  | Usergroups |  Profile |  Messages |  Log in  Register 
Go to product documentation
SQL Comparison SDK Previous Versions
SQL Comparison SDK Previous Versions forum

Memory Issues with large syncs

Search in SQL Comparison SDK Previous Versions forum
Post new topic   Reply to topic
Jump to:  
Author Message
MarkLFT



Joined: 22 Apr 2011
Posts: 10
Location: Bali, Indonesia

PostPosted: Mon Feb 20, 2012 7:55 am    Post subject: Memory Issues with large syncs Reply with quote

I am using the SDK in a Windows Service, to, based on a timer, sync two databases. The service runs fine but seems to suffer a memory leak. I have tracked this down to occasionally there is a large amount of data to sync. Infact the service memory in Windows grows from 50K to 1.2M. These rises are when the SDK is obtaining the difference.

Usually this memory is released after the sync, but as I said if it is a big sync, the memory is not full released.

I nothice in the sample code it mentions using GetFileStream() to avoid memory issues, but I am not sure how to use the resulting stream, as there is no execute method that takes a stream. Could someone give me an example of how to use the Stream option.

Many thanks
Back to top
View user's profile Send private message
Brian Donahue



Joined: 23 Aug 2004
Posts: 6640

PostPosted: Tue Feb 21, 2012 5:24 pm    Post subject: Reply with quote

Hello,

I don't think there is a way to make this synchronization any more efficient, and if the memory was not returned after use, that would be a memory leak. So there doesn't appear to be a memory leak because the memory is being freed.

Also, you have to be careful to look at the correct metric to determine the memory usage because the .net Framework will not always release memory back to the OS when it is done with it. Most times it keep the memory but marks it as free for use.

The GetFileStream method increases the efficiency of writing the synchronization script to disk only, and won't help you with the synchronization. For instance, if you wantes to write the script to disk without using GetFileStream, you would first have to turn the execution block to a string which will be completely in memory, and then writing that string to disk. Using a FileStream, you can read small bits (512 bytes) and write each buffer to disk instead.

If you have any more questions, please let us know.
Back to top
View user's profile Send private message
MarkLFT



Joined: 22 Apr 2011
Posts: 10
Location: Bali, Indonesia

PostPosted: Wed Feb 22, 2012 2:35 am    Post subject: Reply with quote

Thanks for the reply,but I believe a memory leak is exactly what I have.

If I run the service, but disable the SDK methods that perform the sync, the service always uses exactly the same amount of memory, and runs for extended periods of time with no problems.

However, if I leave the SDK methods in place, the service starts using about 3% of available system memory, within 24 hours that is up to 50%, with two to three days the system crashes as out of memory.

I would say that is the definition of a memory leak irrespective of which metric I use.

Thanks
Back to top
View user's profile Send private message
Brian Donahue



Joined: 23 Aug 2004
Posts: 6640

PostPosted: Thu Feb 23, 2012 5:47 pm    Post subject: Reply with quote

Please remember to call Dispose() on all disposable objects, or enclose your database, session, provider, and other disposable objects in a using block.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic All times are GMT + 1 Hour
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group