Unless you’ve profiled the app and found that memory needed to store the customer list is a noticeable concern for app performance, I would suggest a working hypothesis that this would be somewhere around #724 on my list of stuff to worry about.
People watch videos and play castle tower defense games and edit photos of themselves to look like they are anime characters on the devices your app is likely to be running on. Those sorts of activities absolutely dwarf the storage (and CPU) requirements needed for slinging typical textual data around, even a lot of fairly extensive textual data. If your Customer
does have super-heavy images or videos included in it, keep reading.
Yeah, this is a great question and goes to the heart of just how pathetic JavaScript’s fake “OO” really is. I think I’ve been working in JavaScript (kicking and screaming daily) for almost a decade now and still don’t really have a solid, concise recommendation for how to work with it on this topic.
I’m going to assume you’ve got some familiarity with C or another C-like language, due to your use of the term “address of”. The short answer to your question is “the address of the list”, in the sense that although everything in JavaScript is technically pass-by-value, the “value” of an object (or an array, which is a special kind of object, even though you generally shouldn’t think of them that way) is effectively a pointer in C terms, with all the baggage that goes with that.
Entire libraries like Immutable.js and Redux have sprung up attempting to deal with “when do I want a pointer copy, a shallow clone, or a deep clone?”. I have no experience yet with any of them.
But yes, you have to worry about this. When you call something like sort
that modifies an array in place, everybody else holding a reference to that array gets affected. If that’s a problem, then you can start cloning things or defining ownership rules.
Again, though, textual data is super, super lightweight in today’s world. You are going to have much more urgent performance (and UI) concerns figuring out how to let users interact with lots of customers way before you have to worry about how many copies of the list you have in memory. If a Customer
has heavy fields like a movie or high-res image, worry about those, but unless you’re blindly deep-cloning everything, those heavy bits will effectively be shared by reference.