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 935911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:13:55+00:00 2026-05-15T21:13:55+00:00

Why does this code eat up memory? When I run it it slowly consumes

  • 0

Why does this code eat up memory? When I run it it slowly consumes more memory with every loop, and I have something like 300000 loops. I’m using Windows, and Python 2.6.

def LoadVotes(self):
    old_votes=Votes.objects.all()
    amount=old_votes.count()
    print 'Amount of votes is: ' + str(amount)
    c=0
    for row in old_votes:
        try:
            new_id_user=LegacyUserId.objects.get(legacy_id=row._login)
        except LegacyUserId.DoesNotExist:
            string=" user with old id "+str(row._login)+" does not match new user id /n"
            log=open('log_add_old_votes.txt','a')
            log.write(string)
            continue
        try:
            new_id_media=LegacyMedia.objects.get(legacy_id=row.media_file_id)
        except new_id_media.DoesNotExist:
            log_text='old media with ID:'+str(row.media_file_id)+' is not found in relation with new media \n'
            log=open('log_add_old_votes.txt','a')
            log.write(log_text)
            continue
        mo=MediaObject.objects.get(pk=new_id_media.object_id)
        new_votes_item, created=Mark.objects.get_or_create(user=new_id_user.user, media_object=mo, defaults={'mark':int(row.rate)*2}) 
        c=c+1
        i=amount-c
        print '\rRemain:',
        stdout.write("%d" % i)
        stdout.flush()
  • 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-05-15T21:13:56+00:00Added an answer on May 15, 2026 at 9:13 pm

    If you run with DEBUG=True, django is storing all the queries in memory. Try changing to DEBUG=False in your settings.py file.

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

Sidebar

Related Questions

Does this code cause a memory leak: int main(){ int * a = new
Does this code violate strict aliasing? struct {int x;} a; *(int*)&a = 3 More
Does this code create any memory leaks? Or is there anything wrong with the
Does this code get called for every object creation in Java, because every object
Does this code contain anything invalid. I have a form with a table inside.
Does this code create a memory leak? WebClient client = new WebClient(); client.DownloadDataCompleted +=
Why does this code take a long time to run? SELECT concat((select Sname from
Why does this code take not run? for(int i=0;i<11;i++){ for(int j=0;j<11;j++){ if(i>0){ if((staticWallLoc[i--][j]&4)>0){staticWallLoc[i][j]=staticWallLoc[i][j]|1;} }
Does this code always evaluate to false? Both variables are two's complement signed ints.
Does this code work across all standard compliant C++ compilers (it works with g++)?

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.