Q:

Django memory leak when linking one-to-one fields

I have a model that contains one-to-one fields to other models. I over rid the save method to automatically assign these one-to-one fields. The problem is whenever I save this model, memory usage goes up by about 450k and is never released. The save method is as follows:
class Link(models.model):
   id = models.CharField(max_length=11, primary_key=True)
   fieldOne = models.OneToOneField(One, null=True, editable=False)
   fieldTwo = models.OneToOneField(Two, null=True,, editable=False)
   fieldThree = models.OneToOneField(Three, null=True,, editable=False)

   def save(self, *args, **kwargs):
       self.fieldOne = One.objects.get(id=self.id)
       self.fieldTwo = Two.objects.get(id=self.id)
       self.fieldThree = Three.objects.get(id=self.id)

       super(Link, self)save(*args, **kwargs)

I believe the memory leak occurs at the line when objects.get() is called, since when I comment tem out, I noticed no increase in mem usage.

A:

Are you running with DEBUG on?  DEBUG has nasty repercussions on memory usage.
Check out the docs on on memory leaks:
http://docs.djangoproject.com/en/dev/faq/models/#why-is-django-leaking-memory

