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

  • Home
  • SEARCH
  • 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 6177563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:17:52+00:00 2026-05-24T00:17:52+00:00

Somehow the memory my Python program takes more and more memory as it runs

  • 0

Somehow the memory my Python program takes more and more memory as it runs (the VIRT and RES) column of the “top” command keep increasing.

However, I double checked my code extremely carefully, and I am sure that there is no memory leaks (didn’t use any dictionary, no global variables. It’s just a main method calling a sub method for a number of times).

I used heapy to profile my memory usage by

from guppy import hpy;
heap = hpy();
.....
print heap.heap();

each time the main method calls the sub method. Surprisingly, it always gives the same output. But the memory usage just keeps growing.

I wonder if I didn’t use heapy right, or VIRT and RES in “top” command do not really reflect the memory my code uses?

Or can anyone provide a better way to track down the memory usage in a Python script?

Thanks a lot!

  • 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-24T00:17:53+00:00Added an answer on May 24, 2026 at 12:17 am

    Two possible cases:

    • your function is pure Python, in which case possible causes include

      • you are storing an increasing number of large objects
      • you are having cycles of objects with a __del__ method, which the gc won’t touch

      I’d suggest using the gc module and the gc.garbage and gc.get_objects function (see http://docs.python.org/library/gc.html#module-gc), to get list of existing objects, and you can then introspect them by looking at the __class__attribute of each object for instance to get information about the object’s class.

    • your function is at least partially written in C / C++, in which case the problem potentially is in that code. The advice above still applies, but won’t be able to see all leaks: you will see leaks caused by missing calls to PY_DECREF, but not low level C/C++ allocations without a corresponding deallocation. For this you will need valgrind. See this question for more info on that topic

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

Sidebar

Related Questions

I would like to update my SQL lite database with the native update-method of
I'm trying to build a Chrome browser extension, that should enhance the way the

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.