Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8965913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:54:51+00:00 2026-06-15T16:54:51+00:00

Is it better to store objects or reference to objects in an other object

  • 0

Is it better to store objects or reference to objects in an other object ?
Let me explain with an example.

I have one object “Team” and one object “Unit”
the unit belong to the team.
I want to “store” the object “unit” in my object “team”.

1) I can do something like this : the units are stored in the team object

// class Team
function Team() {
    this.units = [];
}
// class Unit
function Unit(team) {
    team.units.push(this);
}
myTeam = new Team();
units = [];
units[units.length] = new Unit( myTeam );

2) Or something like this : the units id are stored in the team object

// class Team
function Team() {
    this.units = [];
}
// class Unit
function Unit(team, id) {
    team.units.push(id);
}
myTeam = new Team();
units = [];
units[units.length] = new Unit( myTeam, units.length );

is it understandable ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T16:54:52+00:00Added an answer on June 15, 2026 at 4:54 pm

    If your concern is that storing objects will take up more memory, this is incorrect.

    An object in Javascript is a unit of data stored somewhere in memory, but when you are adding objects in the first code sample you are merely adding a reference to that piece of memory: you are not creating a copy of the object (which would double memory usage). There is no performance benefit in the second approach as far as storage is concerned.

    Now, let us address design. Many times, I have used associating arrays and the like, where the id of objects are not part of their set of fields. This has invariably lead to more complicated code because there always came a time where I needed to pass the object somewhere but also its id. Unless there are special circumstances that dictate otherwise, it usually makes perfect sense that the id be considered to be part of the object. A design decision that makes sense at the conceptual level is likely to lead to better design choices further on.

    So my vote is definitely for alternative 1.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose that you have to set 12 cookies, would it be better to store
This is an attempt to better understand how reference count works in Python. Let's
Generally, I had thought it was always better to store images in the filesystem
Is there a better way to format data uniformly than to store data as
Better to give an example, to illustrate what i am describing. The div element
I have a bunch of NSDictionaries thats stored in an NSArray. The dictionaries store
I have a few sites with Twitter & Facebook Feeds, and one that references
I have three layers, the bottom layer is written in C++ and the other
is it possible in Db4o to load new objects into persistent IObjectContainer? I have
I'm attempting to create an html element as a jQuery object, and then reference

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.