• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Aggregation in Java

 
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

while reading an example for Aggregation .
I got with this from a site .

"My Object consists of other Objects which can live even after MyObject is destroyed ".

Now my question will this be not a memory leak ?

Aggregation: Life times of the objects are not the same, one object can live even after the other object has been destroyed.

Please Can i get a java example for the above statement .
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What about Strings which are coded as literals? They remain in the String pool until the class has been unloaded.
What about something which has a second reference in another class, maybe a List?
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you.

The first point made by you explains nice.
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ravi Kiran V wrote:Now my question will this be not a memory leak ?


Only if the remaining references should not be there (which is a programming error), but mostly objects remain because they are still needed. That means it's not a memory leak since that means the objects are not needed at all but still use memory.
 
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ravi Kiran V wrote:
My Object consists of other Objects which can live even after MyObject is destroyed ".

Now my question will this be not a memory leak ?



This is a misunderstanding. Aggregation is a design relationship. It has nothing to do with the disposal of objects when they're no longer used.

Ordinary composition describes how a class is constructed from other classes. Aggregation composition on the other hand describes the temporary relationships a class can form.

One example is a Car. A Car is constructed from of its Parts. It owns them. If a Part is misssing the Car is broken. Car forms a composition relationship with its Parts.

But a Car also can have Passengers. The Passengers aren't Parts of the Car. When a Passenger is missing the Car isn't broken. The Car doesn't own its Passengers. When they're not in the Car they're elsewhere. The relationship is temporary. Passengers come and go. Car forms an aggregation relationship with its Passengers.

Note that both are composition relationships really. A Car has Parts and it has Passengers. The difference is the duration. The relationship with Parts is forever whereas the relationship with Passengers is temporary.
 
Is this the real life? Is this just fantasy? Is this a tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic