开发者

Django memory leak when linking one-to-one fields

开发者 https://www.devze.com 2022-12-21 04:33 出处:网络
I have a model that contains one-to-one fields to other models. I ove开发者_开发百科r rid the save method to automatically assign these one-to-one fields. The problem is whenever I save this model, me

I have a model that contains one-to-one fields to other models. I ove开发者_开发百科r 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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号