为什么简单的Django迭代表有内存泄漏

时间:2017-09-15 22:47:58

标签: django memory-leaks

我有一个简单的Django项目来迭代一个表,如下所示:

from myprojectmodule import models 

if __name__ == '__main__':
  if not settings.configured:
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')
  django.setup()


  for item in models.mytable.objects.all():
    print item

内存泄漏如下:

    Warning:  160 bytes lost at 0x65bc980, allocated by T@0 at 
        @     0x7f5f0327d075  my_malloc
        @     0x7f5f0321a95e  mysql_options
        @     0x7f5f0321dfa5  set_connect_attributes
        @     0x7f5f0321c1df  mysql_real_connect
        @     0x7f5f192f281b  _mysql_ConnectionObject_Initialize
        @           0x49ccdf  wrap_init
    Memory lost: 17536 bytes in 15 chunks

如何避免它?缺少什么来避免内存泄漏。

0 个答案:

没有答案