• 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

Code Optimization

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

In a list i am adding anonymous objects, and the list is again referenced by another object.

If i add anonymous objects to a list, will it cause any memory leakage problems(not collected by gc).

 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch
Your thread title doesn't actually tell us what the thread is about.

You will only get memory leaks if you have unnecessary references to your objects. If they are in a List, they must be necessary references, but I presume you remove them from the List so they can be garbage-collected. If they are anonymous objects, they will have no references elsewhere . . .
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

shanmukhan battinapati wrote:
If i add anonymous objects to a list, will it cause any memory leakage problems(not collected by gc).



The garbage collection will collect any object that is no longer reachable. So the only way to "leak", is for you to accidentally forget that the object is in the list, and not remove it (assuming that the list remains reachable, of course).

Henry
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic