Why doesn't memory get released to system after large queries (or series of queries) in django?

后端 未结 2 1557
轻奢々
轻奢々 2020-12-02 19:15

First off, DEBUG = False in settings.py, so no, connections[\'default\'].queries is not growing and growing until it uses up all of memory.

2条回答
  •  囚心锁ツ
    2020-12-02 19:33

    Lots of applications, language runtimes, and perhaps even some system memory allocators will keep deallocated memory in place for as long as possible with a view to re-using it, purely for performance purposes. In a complex system like Django it could be any number of extensions, possibly implemented in C, which exhibit this behaviour, or it might be Python with some sort of memory pool, or lazy garbage collection.

    It could even be the underlying malloc implementation doing this, or your operating system keeping a certain amount of memory space allocated to your process even though the process isn't explicitly using it. Don't quote me on this though - it's been a while since I looked into such things.

    On the whole though, if repeating the allocation process after the initial alloc and dealloc does not double the amount of memory used, what you're seeing is not a memory leak but memory pooling. It's only likely to be a problem if you have a lot of processes that contend for a limited amount of memory on that machine.

提交回复
热议问题