Unlike many other languages, Python does not necessarily release the memory back to the Operating System. Instead, it has a dedicated object allocator for objects smaller than 512 bytes, which keeps some chunks of already allocated memory for further use in the future. The amount of memory that...
it has a dedicated object allocator for small objects (smaller or equal to 512 bytes), which keeps some chunks of already allocated memory for further use in the future. The amount of memory that Python holds depends on the usage patterns. In some cases, all allocated...
Keep in mind these are Python objects that have some overhead in the first place. (sys.getsizeof('') will return 49 bytes.) There is also colors.memory_usage(), which sums up the memory usage and relies on the .nbytes attribute of the underlying NumPy array. Don’t get too bogged ...
Since I started learning Python, I've kept a list of "tricks". Any time I saw a piece of code that made me think "Cool! I didn't know you could do that!" I experimented with it until I understood it and added it to the list. This post is a summary of that list. If you ar...