Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak in long running transaction #2407

Open
laurentthiebaudezm opened this issue Feb 14, 2025 · 0 comments
Open

Memory leak in long running transaction #2407

laurentthiebaudezm opened this issue Feb 14, 2025 · 0 comments

Comments

@laurentthiebaudezm
Copy link

laurentthiebaudezm commented Feb 14, 2025

Hi,

Using pgsql & suspended transactions in dsl mode, we have a long running transaction with a loop, e.g.

  transaction {
   var doContinue = true
    while (doContinue) {
       val toProcess = getDbElementsToProcess()
       processElements(toProcess)
       if (toProcess.isEmpty()) doContinue = false
    }
  }

If we have a huge number of elements to process (> 100 000) and the transactions lasts few minutes, we can eventually have an Out Of Memory. Looking in VisualVM, we see this is caused by multiple PreparedStatements that are never garbage collected.

Yet if we open a new transaction on each loop run, we don't have troubles anymore. e.g.

   var doContinue = true
    while (doContinue) {
       transaction {
          val toProcess = getDbElementsToProcess()
         processElements(toProcess)
         if (toProcess.isEmpty()) doContinue = false
       }
    }

From another post, we understood that closing the transaction does close all prepared statements and free the memory.

However we'd like to avoid having to open a new transaction on each loop run. Is there any way to close prepared statements properly, optionally manually?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant