I have an sqlalchemy query that returns a tuple. I pass this tuple to a function, and since it's an immutable type, a new instance of the tuple is created in the called function.
How does python deal with this in terms of memory management? Is a complete copy of the tuple created, or is it using some clever 'copy on write/zero copy' like functionality?
The problem for me is that these original tuples can consume large amounts of memory, and just by calling a function to do some processing on them, Python will effectively double the memory consumption.
With the exception of writing the code inline, how can I avoid such inefficiency?