Re: How to release the caching of QuerySet
On Wed, Apr 18, 2012 at 11:05 AM, Kejun He <printerhkj@gmail.com> wrote:
> Hi,
>
> I met a problem about memory overflow on a Django project.
> I spent much of time finding the reason and I got some question about how
> the
> django release the caching of QuerySet.
>
> Exp:
> I build a Model class like below:
>
> class Demo(models.Model):
> pid = models.IntegerField()
>
> and define a method named test in views.py. like below:
>
> def test(p_id):
> # Just execute the filter 1000 times
> for i in xrange(1000):
> Demo.objects.filter(pid=p_id)
>
> then run "python manage.py syncdb" to build the table structure.
>
> Enter python shell through "python manage.py shell"
>
> Call the method test():
>>>>from Demo.views import test
>>>>test(1)
>>>>
>
> Then I found the memory occupied by python increase.
> run the test function again:
>>>>test(1)
> The occupied memory increase again.
>
> But the memory never been released until I input exit() to quit the python
> shell.
>
> I have checked the Django document about caching of QuerySet.
> https://docs.djangoproject.com/en/1.2/topics/db/queries/#caching-and-querysets
> And I think the same QuerySet would be cached just one time; and the other
> 999 times
> would not be cached, the result should come from the caching of the first
> QuerySet.
>
>
> I could not understand why the occupied memory just increase when I execute
> the code "Demo.objects.filter(pid=p_id)" for 1000 times.
>
> Did I make a mistake on understanding caching of QuerySet?
>
> How to release the occupied memory manually?
>
> PS:
> Django version: 1.2
>
> Could you help me?
>
> sorry for my poor English, thanks before.
>
> Regards,
> Kejun
>
Do you have settings.DEBUG set to True? If so, memory leaks are to be
expected, not everything is cleaned away at the end of a request, by
design.
Cheers
Tom
--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home