#16022: Cyclic reference in FieldFile causes memory usage to grow considerably
-------------------------------------+-------------------------------------
               Reporter:  Gustavo    |          Owner:  nobody
                   Type:  Bug        |         Status:  closed
              Milestone:             |      Component:  Database layer
                Version:  1.1        |  (models, ORM)
             Resolution:             |       Severity:  Normal
  worksforme                         |       Keywords:  memory leak
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |    Needs tests:  0
    Needs documentation:  0          |  Easy pickings:  0
Patch needs improvement:  0          |
-------------------------------------+-------------------------------------
Changes (by aaugustin):

 * status:  new => closed
 * resolution:   => worksforme


Comment:

 OK, I tried to reproduce this seriously. I created a project called
 `madupload` and an app called `receiver` inside.
 {{{

 madupload
 ├── __init__.py
 ├── manage.py
 ├── receiver
 │   ├── __init__.py
 │   ├── models.py
 │   ├── views.py
 ├── settings.py
 └── urls.py
 }}}

 `receiver/models.py`:
 {{{
 from django import forms
 from django.db import models

 class UploadModel(models.Model):
     upload = models.FileField()

 class UploadForm(forms.ModelForm):
     class Meta:
         model = UploadModel
 }}}

 `receiver/views.py`:
 {{{
 from django.http import HttpResponse
 from django.views.decorators.csrf import csrf_exempt

 from .models import UploadForm

 @csrf_exempt
 def upload(request):
     form = UploadForm(request.POST, request.FILES)
     try:
         model = form.save(commit=False)
         return HttpResponse("Saved %i bytes.\n" % model.upload.size,
                 status=201, content_type='text/plain')
     except ValueError:
         return HttpResponse(repr(form.errors) + "\n",
                 status=400, content_type='text/plain')
 }}}

 `urls.py`:
 {{{
 from django.conf.urls.defaults import patterns, url

 urlpatterns = patterns('',
     url(r'^$', 'receiver.views.upload'),
 )
 }}}

 All other files are unchanged from Django's template.

 Then I launched `runserver` and started uploading:

 {{{
 myk@mYk madupload % dd if=/dev/random of=1mb.bin bs=1024 count=1024
 1024+0 records in
 1024+0 records out
 1048576 bytes transferred in 0.146655 secs (7149958 bytes/sec)
 myk@mYk madupload % while true; do curl -F "[email protected]"
 http://localhost:8000; done
 Saved 1048576 bytes.
 Saved 1048576 bytes.
 Saved 1048576 bytes.
 ...
 }}}

 I've let it run more than one hundred of uploads, and the memory footprint
 of the Python process handling `runserver` is flat.

 At this point, I have proven that the cyclic reference in !FileField is
 not a problem in itself.

 I still don't know what's causing your bug. You may have a global variable
 referencing  your !FileField objects somewhere.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/16022#comment:6>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to