Why using chunk cause memory leaking? #43866
Unanswered
lamkimphu258
asked this question in
Q&A
Replies: 1 comment 3 replies
-
Well as you can see in the source of the chunk method, it is unsetting the previous chunk before loading the next chunk. It is not actually freeing memory perse, it is only clearing what it loaded before your chunk code is run. That means somewhere in your code you are somehow storing the results in memory again and it is not automatically clearing on the next iteration. Maybe you are using a singleton class instance that stores the models inside it. If you would like to share the code you are using and we can try and debug it. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Version
Hardware Specification
Problem
I have a table in database which has nearly 7 millions record. For that reason, I need to write a command to sync data from MySQL to Elasticsearch to query faster. When I use chunk in my command, RAM usage is increased time by time and as you can guess, it is out of memory when I have not finished to sync data yet. Change to use Queue Job solve the problem.
I thought that chunk will load a chunk of data -> do something -> free memory -> load another chunk of data. But maybe, its step is load a chunk of data -> do something -> load another chunk of data. Why chunk doesn't free memory each time it finish a chunk of data and cause memory leaking?
Beta Was this translation helpful? Give feedback.
All reactions