Skip to content

Instantly share code, notes, and snippets.

@baxeico
Created September 30, 2014 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baxeico/ced5e8b6a410dc1d842f to your computer and use it in GitHub Desktop.
Save baxeico/ced5e8b6a410dc1d842f to your computer and use it in GitHub Desktop.
Fixing a memleak in a Django view
from django.http import HttpResponse
from .models import FirstModel
def my_view(request):
# this queryset contains about 100k records
# each of them has many ForeignKeys to other models
huge_queryset = FirstModel.objects.all().iterator()
f = open('dumb.dump', 'w')
for record in huge_queryset:
print >>f, record
f.close()
return HttpResponse('Dumb dump completed!')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment