Opened 10 years ago

Closed 10 years ago

#21953 closed Bug (invalid)

Memory leak in 1.6.1 in DB manager

Reported by: steve.hutchinz@… Owned by: nobody
Component: Database layer (models, ORM) Version: 1.6
Severity: Release blocker Keywords: memory leak DB manager
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Tim Graham)

Since upgrading from 1.4 to 1.6.1 my app is consuming memory rather rapidly.
I have this issue on both my live Ubuntu 64bit server (python 2.7.5+, django 1.6.1) and on my development Windows 7 32bit (python 2.7.3, django 1.6.1)

After some diagnosis I have created a minimal test app that replicates this issue which I can replicate using both SQLite and Postgresql (9.3, psycopyg2 2.5.2) either using the model manager or raw sql connection.

Here's my test model and test python app. The settings are plain standard with the addition of the 'app1' application:
(I know that the two different test functions do not return the same objects - this is just test code)

model:

from django.db import models

class Customer(models.Model):
    name = models.CharField(max_length=256,unique=True)

    class Meta:
        ordering = ["id"]
        app_label = 'app1'

test:

import os
import sys

SETTINGS  = "testsqlite.settings"
THE_PATH = r'D:\dev\django\testsqlite'

os.environ["DJANGO_SETTINGS_MODULE"] = SETTINGS
sys.path.append(THE_PATH)

from django.db import connection
from django.core.exceptions import ObjectDoesNotExist

from models import Customer

def GetCustomerSQL(name):
    cursor = connection.cursor()
    sql = "SELECT id FROM app1_customer WHERE name = '%s'" % name
    cursor.execute(sql)
    customer = cursor.fetchone()
    del cursor
    return customer

def GetCustomer(name):
    customer = None
    try:
        customer = Customer.objects.get(name=name)
    except ObjectDoesNotExist:
        pass
    return customer

while 1:
    #customer = GetCustomerSQL('Steve')
    customer = GetCustomer('Steve')
    del customer

Change History (3)

comment:1 by Tim Graham, 10 years ago

Description: modified (diff)
Severity: NormalRelease blocker

Added some formatting (please use preview) and tentatively marking as a release blocker to indicate the fix should be backported assuming this is confirmed to be a bug in Django.

comment:2 by Claude Paroz, 10 years ago

I was unable to reproduce the leak (Debian Wheezy, Python 2.7.3, PostgreSQL 9.1, Django 1.6.1).
Are you completely sure that DEBUG is False when you test?

comment:3 by steve.hutchinz@…, 10 years ago

Resolution: invalid
Status: newclosed

Hey look I am really sorry to have wasted your time on this. Although my app is leaking on Ubuntu I thought I had narrowed it down on my test Windows box but didn't realise that DEBUG was True (sheepish grin). So I will continue looking and leave you in peace :)

Note: See TracTickets for help on using tickets.
Back to Top