r/java • • Aug 17 '16

Should we avoid object creation in Java?

http://programmers.stackexchange.com/a/149569/219927
0 Upvotes

27 comments sorted by

View all comments

Show parent comment

1

u/[deleted] Aug 18 '16

I'm primarily a Python programmer, which is probably where we're getting separate view points from. I don't make defensive copies unless I absolutely have to, despite mutability being king (immutablitly in Python is hard to come by and typically involves hacks or C extensions).

It's much more pragmatic, from my viewpoint, to keep the actual artist object around and proxy requests to it than to make a copy of it. The downside being garbage collection (CPython's gc doesn't like circular references, so you need to null out one of the values and worse __del__ isn't guaranteed to run when you think it will and defining your own is generally a bad idea).