3/29/2023 0 Comments Memory clean 3 upgrade code![]() ![]() The first modified array, created by modify1() this hangs around until modify2() has finished using it and then gets deallocated. ![]() ![]() The original array created by load_1GB_of_data().If we profile it with the Fil memory profiler to get allocations at the time of peak memory usage, here’s what we’ll get:Īt peak we use 3GB due to three allocations basically we’re looking at the moment in time when modify2() allocates its modified array: Let’s return to our original code, where we had an unexpected extra 1GB of memory usage.ĭef process_data (): data = load_1GB_of_data () return modify2 ( modify1 ( data )) def modify1 ( data ): return data * 2 def modify2 ( data ): return data + 10 Now, keeping a small dictionary in memory for slightly longer isn’t really a problem.īut what if that object used a lot of memory? The extra 1GB The local variable’s reference will never go away until f() exits, even though f() is done using it. Once the dictionary is passed to g(), it will never be used by f() again-and yet, there is still a reference from f() due to the obj variable, which is why the reference count is 2. Now let’s look at that code again, on a semantic level. ![]() This also decrements the reference count for the "x" string and the 1 integer we created, modulo some string- and integer-specific optimizations I won’t go into.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |