Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8811035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:15:49+00:00 2026-06-14T03:15:49+00:00

I have a table containing about 30k records, that I’m attempting to iterate over

  • 0

I have a table containing about 30k records, that I’m attempting to iterate over and process with Django’s ORM. Each record stores several binary blobs, which can each be several MB in size, that I need to process and write to a file.

However, I’m having trouble using Django for this because of memory constraints. I have 8GB of memory on my system, but after processing about 5k of records, the Python process is consuming all 8GB and gets killed by the Linux kernel. I’ve tried various tricks for clearing Django’s query cache, like:

  1. periodically calling MyModel.objects.update()
  2. setting settings.DEBUG=False
  3. periodically invoking Python’s garbage collector via gc.collect()

However, none of these seem to have any noticeable effect, and my process continues to experience some sort of memory leak until it crashes.

Is there anything else I can do?

Since I only need to process each record one at a time, and I never need to access the same record again in the process, I have no need to save any model instance, or load more than one instance at a time. How do you ensure that only one record is loaded and that Django caches nothing and unallocates all memory immediately after use?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T03:15:51+00:00Added an answer on June 14, 2026 at 3:15 am

    Try to use iterator.

    A QuerySet typically caches its results internally so that repeated
    evaluations do not result in additional queries. In contrast,
    iterator() will read results directly, without doing any caching at
    the QuerySet level (internally, the default iterator calls iterator()
    and caches the return value). For a QuerySet which returns a large
    number of objects that you only need to access once, this can results
    in better performance and a significant reduction in memory.

    It’s a quote from django docs: https://docs.djangoproject.com/en/dev/ref/models/querysets/#iterator

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, so I have a table containing information about jobs. The goal is that
Say I have at database table containing information about a news article in each
I have a table containing data about some users. Many of them use our
I have two large tables in MySQL, one containing about 6,00,000 records and another
I have a table containing view/click records. The time is stored in a unix
I have 3 tables. An Applications (relevant field is AppID) table containing information about
I have a MySQL table containing phone numbers that may be formatted in many
I have a table containing a large number of rows. Each row has 2
I have data containing about 30 000 records. And I need to insert this
I have table containing information about a series of x number of quizzes. It

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.