WiseLibs / better-sqlite3

The fastest and simplest library for SQLite3 in Node.js.
MIT License
5.23k stars 390 forks source link

How can I fully release all of its memory #1156

Closed Super-Badmen-Viper closed 4 months ago

Super-Badmen-Viper commented 4 months ago

I want to release memory after using better-sqlite3. After I close it, the "open" property is false, but the memory usage is not released. It consistently remains around 160MB in my application.

let path = require('path'); let Database = require('better-sqlite3'); let db = new Database(path.resolve('resources/navidrome.db'), { verbose: console.log }); db.pragma('journal_mode = WAL'); db.close() console.log('db.open?:'+db.open)

As mentioned above, I found that even after closing, it still exists in my application memory. I need to use and fetch (better-sqlite3) as needed, and I don't want (better-sqlite3) to remain in my memory all the time

mceachen commented 4 months ago

In the future, know that any open source project you engage with will be much more receptive to issues that contain an easy way to reproduce the issue.

  1. How are you measuring memory consumption?
  2. What version of node are you using?
  3. What's your OS?
  4. Can you provide a link to your db?

Keep in mind that node/v8 memory management is very noisy -- the GC is stochastic, when it runs, and what it does really depends on your system and setup.

PhotoStructure (which uses this library) regularly hosts 250MB+ library databases, and there are cases when I need to close and reopen the database. When using chrome's memory inspector, node's memory consumption doesn't monotonically grow, so I suspect your process memory will get released eventually once the GC decides to run.

Super-Badmen-Viper commented 4 months ago

In the future, know that any open source project you engage with will be much more receptive to issues that contain an easy way to reproduce the issue.

  1. How are you measuring memory consumption?
  2. What version of node are you using?
  3. What's your OS?
  4. Can you provide a link to your db?

Keep in mind that node/v8 memory management is very noisy -- the GC is stochastic, when it runs, and what it does really depends on your system and setup.

PhotoStructure (which uses this library) regularly hosts 250MB+ library databases, and there are cases when I need to close and reopen the database. When using chrome's memory inspector, node's memory consumption doesn't monotonically grow, so I suspect your process memory will get released eventually once the GC decides to run.

I seem to have grasped your meaning. I should try to gain a better understanding of the memory management characteristics of Node.js, especially the uncertainties of V8's garbage collection (GC) mechanism. I should attempt to perform appropriate operations on better-sqlite3 at the appropriate places to facilitate better memory reclamation by the GC for my code. Thank you for your reply.