You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Zhang, Larry (L.)" <lz...@ford.com> on 2004/10/25 16:34:58 UTC

Object size/memory usage

Let's say I have two object

public calss Object1{
	private name;
	private id;
	private depetId;

}

public calss Object2{
	private name;
	private id;
	private depetId;
	private country;
	private jobFamily;
	private isActive;
      ..... (there are another 100 attributes)

}

Then I create 

Object1 obj1= new Object1(); and set all attributes (name, id, depetId)
of this object.
Object2 obj2 = new Object2(); and then set the first three
attributes(name, id, depetId).

My question is that is obj1 and obj2 of the same size or usage of
memory?

Thanks.

               

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Object size/memory usage

Posted by Guillaume Lederrey <Ge...@LedCom.ch>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Monday 25 October 2004 16.34, Zhang, Larry (L.) wrote:
> Let's say I have two object
>
> public calss Object1{
>  private name;
>  private id;
>  private depetId;
>
> }
>
> public calss Object2{
>  private name;
>  private id;
>  private depetId;
>  private country;
>  private jobFamily;
>  private isActive;
>       ..... (there are another 100 attributes)
>
> }
> Object1 obj1= new Object1(); and set all attributes (name, id, depetId)
> of this object.
> Object2 obj2 = new Object2(); and then set the first three
> attributes(name, id, depetId).
>
> My question is that is obj1 and obj2 of the same size or usage of
> memory?

  No, object 2 will take more memory.

  If your attributes are primitive types (int, boolean, ...), they will be
allocated at the object creation. If your attributes are Objects, the
reference will be allocated at object creation, but the object the reference
is pointing to will not be allocated.

  I dont know what's the exact size of a reference in Java (probably 32 or 64
bits). Anyway, the size of the ref is probably small compared to the size of
an allocated object (depends on the size of your object).

  I hope it answers your question ...

 Guillaume Lederrey
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFBfgH0W+xV6X6No3gRApeeAKDUnk9x2MI5BI5bVLA72ndeWoa5/QCbBY0U
IQM2kZkmfljZjGSGFRi1h8E=
=zM/T
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org