Mimsy Were the Borogoves

Hacks: Articles about programming in Python, Perl, Swift, BASIC, and whatever else I happen to feel like hacking at.

Django using too much memory? Turn off DEBUG=True!

Jerry Stratton, June 14, 2009

When the Django docs say to turn off DEBUG in settings.py to save memory, they’re not talking peanuts. Over the weekend I imported the largest section of my old blog to my new Django blog, and the command-line script to publish these pages crashed with a MemoryError: “*** error: can't allocate region”.

I ran the script again and watched memory use in top. After a few hundred pages, my 1.5 gigabytes of free memory had dropped to under 10. A quick Google search indicated that the first thing to do when Django has memory problems is turn off DEBUG in settings.py. I did that this morning, and free memory, after scaring me by dropping considerably in the first few minutes, hovered around 1.4 gig for the rest of the process’s life. The Python process, which had grown to over a gigabyte last night, remained at 54 megabytes throughout the upload process.

I’d have to say that DEBUG is meant only for debugging immediate issues and should never be used for long-term development.

  1. <- Django Twitter
  2. Listed code to plaintext ->