I'm sure this question (or something similar) has been asked elsewhere, but I couldn't find it, so this is the (slightly simplified) flow for my android app:
Actvity A: Parses a json file and stores resulting objects in a List (let's call it "raw"). Once done, runs Activty B.
Activity B: A search screen. Button click runs Activity C
Activity C: Filters the list made in Activity A according to search parameters from Activity B. Adds the filtered objects to another list (for use in Activity D - let's call that "filtered") and creates another object based on their values (for use in Activity E - let's call that bigObj). Just in case how bigObj is created is relevant, say I start with objects like this:
filtered = [{"name":"Dave", "age":"32", "job":"boss"},
{"name":"Dave", "age":"32", "job":"worker"},
{"name":"Dave", "age":"24", "job":"boss"},
{"name":"James", "age":"26", "job":"boss"},
{"name":"James", "age":"26", "job":"boss"},
{"name":"James", "age":"65", "job":"boss"}]
then I end up with an object like this:
bigObj = {"Dave":{"32":[{"name":"Dave", "age":"32", "job":"boss"},
{"name":"Dave", "age":"32", "job":"worker"}],
"24":[{"name":"Dave", "age":"24", "job":"boss"}]
},
"James":{"26":[{"name":"James", "age":"26", "job":"boss"},
{"name":"James", "age":"26", "job":"boss"}],
"65":[{"name":"James", "age":"65", "job":"boss"}]
}
}
And all three of these get saved via setters on the application activity.
Later, depending on user interaction in either Activity D or E, the contents of the smaller object - say for example {"name":"Dave", "age":"32", "job":"boss"} - get displayed to the user in Activity F.
Which all works fine. But there's obvious repetition. If an object makes it through the filter, it appears in all 3 places. And being that the objects contain alot more information than is actually needed in Activities D or E, there seems to be alot of data getting passed around needlessly. Which brings me to my question:
Say that "raw" has 100 objects in it, and 50 pass the filter. Are there now 150 objects in memory, or are the 50 that get put into "filtered" just references to the originals?
Because the other way to do it (it would seem) would be simply to use "filtered" to store the indices that the objects appear at in "raw" (and retrieve the actual objects on the fly from "raw" in Activity D) and then, when making "bigObj" to make new "mini objects" that contain just the information that Activity E needs - from the above example the name and age values, plus the object's position in "raw", which can then be used to retrieve the object in Activity F.
But then if the objects are just stored by reference in "filtered" and "bigObj", making a whole set of "mini objects" would actually be counter productive, and end up chewing into memory rather than saving it.
Thanks for any thoughts. I suspect that this question could have been asked alot more simply, but I don't know enough to know what's relevant and what's not...
==would evaluate totrue.