Skip to content

Instantly share code, notes, and snippets.

@narfdotpl
Created August 30, 2011 13:47
Show Gist options
  • Save narfdotpl/1180921 to your computer and use it in GitHub Desktop.
Save narfdotpl/1180921 to your computer and use it in GitHub Desktop.
memory leak in a Django app
# source of a massive memory leak in a Django app (if obj is QuerySet):
if not obj:
return None
@narfdotpl
Copy link
Author

@aerosol: if this will do as context... ;)

This is an oddity I don't understand (I don't know why evaluated queryset wouldn't get GCed), but unfortunately I don't have time to examine it in laboratory conditions. All I can tell is that it was inside a helper function called from a view, which was passing paginator.object_list as obj.

For 99% leak was caused by applying not operator to a QuerySet instance:

# no leak
return None
if not obj:
    return None
# leak
if not obj:
    return None
return None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment