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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:10:47+00:00 2026-05-28T15:10:47+00:00

Suppose you do the following: dom = ElementTree() dom.parse(some_file_path) I’d like to log the

  • 0

Suppose you do the following:

dom = ElementTree()
dom.parse(some_file_path)

I’d like to log the rough amount of memory that this dom is now using in my process. I don’t need something precise, something rough would do.

I don’t think I can derive it from the size of the source XML file. I have a 500 kilobyte file that seems to add about 5MB to the memory usage of my python process after it’s loaded as in the example above.

I looked over the ElementTree API and didn’t see any API to provide this information. Anyone know of a way to know how much memory the ElementTree instance is using after parsing/loading an XML file?

  • 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-28T15:10:48+00:00Added an answer on May 28, 2026 at 3:10 pm

    Essentially you want to find memory consumption of a particular python object. That’s what it is. Here its an ElementTree object but it can be anything.

    To cut the chase short as far as I know There’s no easy way to find out the memory size of a python object. One of the problems you may find is that Python objects – like lists and dicts – may have references to other python objects (in this case, what would your size be? The size containing the size of each object or not?). There are some pointers overhead and internal structures related to object types and garbage collection. Finally, some python objects have non-obvious behaviors. For instance, lists reserve space for more objects than they have, most of the time; dicts are even more complicated since they can operate in different ways (they have a different implementation for small number of keys and sometimes they over allocate entries).

    • There is a big chunk of code out there to try to best approximate the size of a python object in memory. There’s also some simpler approximations. But they will always be approximations.
    • You may also want to check some old description about PyObject (the internal C struct that represents virtually all python objects).
    • also, PySizer, “a memory profiler for Python,” found at http://pysizer.8325.org/. However the page seems to indicate that the project hasn’t been updated for a while, and refers to…
    • You could give Heapy a try, “support[ing] debugging and optimization regarding memory related issues in Python programs,” found at http://guppy-pe.sourceforge.net/#Heapy.
    • objgraph looks interesting: http://mg.pov.lt/objgraph/
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have the following DOM : <div id=container> <div id=created-by-other-tools>I want this to
Suppose I'm following TDD and using VS/ReSharper. I start out writing a test like
Suppose I have the following HTML snippet: <input type=text id=myinput /> Now I want
Suppose the following HTML: <li class=fooli> <a class=foo href=javascript:foo(this);>anchor</a> </li> <li class=fooli> <a class=foo
Suppose the following situation: A user buys an app this app is removed from
Let's suppose the following use case: for a working example plese look at this
This is a completely theoretical question. Suppose the following code: >>> class C: ...
Suppose the following data schema: Usage ====== client_id resource type amount Billing ====== client_id
Suppose the following scenario: I have a master database that contains lots of data,
suppose the following extension methods: public static string ToFooBarString(this object obj) { ... }

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.