Difference between __sizeof__() and getsizeof() method - Python Last Updated : 12 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report We have two Python methods, __sizeof__() and sys.getsizeof(), both used to measure the memory size of an object. While they seem similar, they produce different results. For example, calling these methods on the same object may return different values. Understanding this difference is essential for efficient memory management especially in large-scale applications. Let's explore how these methods work and what sets them apart.sys.getsizeof() MethodA function from the sys module that measures an object’s size in bytes, including extra memory used by Python’s garbage collector, it calls '__sizeof__()' internally but adds the garbage collector’s overhead—extra memory Python reserves to manage objects. Let's explore it using an example: Python import sys a = [1, 2] # Small list b = [1, 2, 3, 4] # Medium list d = [2, 3, 1, 4, 66, 54, 45, 89] # Larger list print(sys.getsizeof(a)) print(sys.getsizeof(b)) print(sys.getsizeof(d)) Output72 88 120 Explanation:Base Size: In this system an empty list takes 56 bytes, covering its structure and overhead (it can vary from system to sytem).Per Element: Each item adds 8 bytes for a pointer to the value giving output 72, 88 and 120.__sizeof__() MethodPerfect for understanding an object’s true footprint, such as comparing data structures in a performance study. For instance, if you’re testing whether a list, tuple, or set is more memory-efficient for storing a dataset, __sizeof__() reveals their baseline sizes without the garbage collector’s overhead muddying the results. Python w = [1, 2] # Small list x = [4, 5, 7, 9] # Medium list z = [54, 45, 12, 23, 24, 90, 20, 40] # Larger list print(w.__sizeof__()) print(x.__sizeof__()) print(z.__sizeof__()) Output56 72 104 Explanation: Base Size: An empty list takes 40 bytes, just for its basic structure.Per Element: Each item adds 8 bytes for a pointer to the value.Difference between sys.getsizeof() and __sizeof__()Featuresys.getsizeof()__sizeof__()ModuleRequires sys libraryBuilt-inIncludes Overhead ?Yes (e.g., 16 bytes)NoEmpty List Size56 bytes (can vary system to system)40 bytes (can vary system to system)Use CaseReal-world memory useBase object sizeWhen To Use Eachsys.getsizeof(): Use this when you need to assess the total memory usage of an object in a live program. It’s great for tasks like profiling a script handling large datasets or debugging why your application is consuming more RAM than expected. For instance, it helps you see the full impact of a list, including garbage collector overhead, which is key for real-world optimization.__sizeof__(): Turn to this when you want to measure an object’s core size without extra overhead, perfect for performance comparisons or algorithm tuning. It’s handy for analyzing whether a list or tuple is more memory-efficient for a specific task, like storing data in a performance-sensitive project, giving you a clear view of the object’s baseline footprint. Comment More infoAdvertise with us Next Article get_window_size driver method - Selenium Python A ashwinsharmap Follow Improve Article Tags : Python Python-Functions Practice Tags : pythonpython-functions Similar Reads Python: Difference between dir() and help() In Python, the dir() and help() functions help programmers understand objects and their functionality.dir() lists all the attributes and methods available for an object, making it easy to explore what it can do.help() provides detailed information about an object, including descriptions of its metho 4 min read Difference between size and count in Pandas? When dealing with data frames, two commonly used methods are size() and count(). While they might seem similar at first glance, they serve different purposes and produce different results. In this article, we'll explore the What's the differences between size() and count() in Pandas and when to use 4 min read How to find size of an object in Python? In python, the usage of sys.getsizeof() can be done to find the storage size of a particular object that occupies some space in the memory. This function returns the size of the object in bytes. It takes at most two arguments i.e Object itself. Note: Only the memory consumption directly attributed t 2 min read get_window_size driver method - Selenium Python Seleniumâs Python Module is built to perform automated testing with Python. Selenium Python bindings provide a simple API to write functional/acceptance tests using Selenium WebDriver. Selenium is a powerful tool for automating browser actions, and its Python bindings provide a simple yet effective 2 min read size element method - Selenium Python Seleniumâs Python Module is built to perform automated testing with Python. Selenium Python bindings provides a simple API to write functional/acceptance tests using Selenium WebDriver. To open a webpage using Selenium Python, checkout - Navigating links using get method â Selenium Python. Just bein 2 min read Python - Get list of files in directory sorted by size In this article, we will be looking at the different approaches to get the list of the files in the given directory in the sorted order of size in the Python programming language. The two different approaches to get the list of files in a directory are sorted by size is as follows: Using os.listdir( 3 min read Like