<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Felix</title>
    <description>The latest articles on DEV Community by Felix (@felixlast).</description>
    <link>https://dev.to/felixlast</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F61102%2Fdb89b22a-8f6c-4958-a4fc-ca10584a3689.png</url>
      <title>DEV Community: Felix</title>
      <link>https://dev.to/felixlast</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/felixlast"/>
    <language>en</language>
    <item>
      <title>Django Migrations leak memory in DEBUG mode</title>
      <dc:creator>Felix</dc:creator>
      <pubDate>Thu, 02 Jul 2020 08:13:38 +0000</pubDate>
      <link>https://dev.to/felixlast/django-migrations-leak-memory-in-debug-mode-59m</link>
      <guid>https://dev.to/felixlast/django-migrations-leak-memory-in-debug-mode-59m</guid>
      <description>&lt;p&gt;While optimizing a django database migration which iterated over batches of a large table (~40 Mio rows), I noticed that the memory usage would consistently grow. Memory consumption kept growing even after I &lt;code&gt;del&lt;/code&gt;'ed all inner-loop variables and asked the garbage collector to do their work.&lt;/p&gt;

&lt;p&gt;I finally figured out that Django's &lt;code&gt;DEBUG&lt;/code&gt; mode, which is &lt;a href="https://www.dimagi.com/blog/django-orm-memory-leaks-in-debug-mode-73877/"&gt;well known to use up memory&lt;/a&gt; for traceability, has the same effect in migrations, too. Adding the following two lines to your migration ensures smooth, memory-efficient processing, no matter the environment:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;django.conf&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;settings&lt;/span&gt;
&lt;span class="n"&gt;settings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;DEBUG&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



</description>
      <category>django</category>
      <category>migration</category>
      <category>memory</category>
    </item>
  </channel>
</rss>
