0


I have .Net application where the user can open and close many
Sqlite databases files, Once at a time.
And I uses the System.Data.SQLite dll wrapper.
Is the connection.close() is enough while moving from one database to another,
I saw at some places calling the GC.Collect().
How to handle these Database switching correctly?

Thanks, Avi.

Avi ba
  • 441
  • 6
  • 10

1 Answers1

0

There is a detailed explanation of the effects of connection.close() and GC.Collect() here:

System.Data.SQLite Close() not releasing database file

Basically connection.close() only disposes the handle but does not release the DB pointer until the Garbage Collector runs. Please note that GC.Collect() is a heavy operation, if your context switching is too frequent and you don't need to delete the DB file, you might be better letting the pointer in memory and the .Net framework handling it.

My recommendation would be, do some performance testing for both options:

  • With GC.Collect
  • Without GC.Collect

Check latency of the process, memory usage and cpu usage. Make your decision based on the results of your testing.

Good luck!

[EDIT] Reading a bit more about it, I found out this link:

What is the difference between connection.Close() and connection.Dispose()?

According to the question, when using the using statement or calling connection.Dispose() there is no need to call the GC.Collect() method.

Cheers,

Community
  • 1
  • 1
wacdany
  • 991
  • 1
  • 10
  • 19