Hello,

I've noticed that when you iterate over a query set and use a
FileField instance from each model instance, the memory used by the
process increases every time the loop finishes. This happens on the
Web and command-line interfaces.

Say you have the following model:
"""
class Bug(Model):
    patch = FileField(upload_to="whatever")
"""

The following loop will make the process use a lot more memory every
time it's run:
"""
for bug in Bug.objects.all()[:1000]:
    print "- %s" % bug.patch.name
"""

But the following loop won't cause memory to grow at all:
"""
for bug in Bug.objects.all()[:1000]:
    print "- %s" % bug.__dict__['patch']
"""

The mere act of using "bug.patch" causes the problem, regardless of
what member of "patch" you use (e.g., "name", "url"). The same happens
with ImageField and presumably any other subclass of FileField.

According to the "strace" utility, the process doesn't even try to
access the file in any way. In fact, if I remove the files from the
file system, the problem is still present. I've also checked the
Postgres statement logs and the only query issued looks absolutely
fine.

I'm using Python 2.5, Django 1.1.4 and Ubuntu (it also happens on
Debian boxes). I got DEBUG set to False.

I'll continue to look at this to see what's exactly going on here, but
I'm posting here to see if someone could shed some lights. I'll post
my findings.

Cheers.

 - Gustavo Narea.

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

Reply via email to