• 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

Garbage collection when exception happen

 
Ranch Hand
Posts: 59
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi good day all,

I have a question, for example in a method:



the exception will be happening , and how many actually garbage will be collected after the method ends?

is the exception object collected after the method end?


exception will be created by the JVM right ? so should we consider this object in the exam???

thanks !!! (i am going to be crazy!!!)
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've never seen any question which considers an exception object to decide how many objects are eligible for GC, but the answer to your question would be 1 object is eligible for GC...
 
jamil lusa
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ankit Garg wrote:I've never seen any question which considers an exception object to decide how many objects are eligible for GC, but the answer to your question would be 1 object is eligible for GC...



hi, i have seen one question in whizlab preparation kit regarding to this garbage collection. it didn't consider the exception object as garbage also.


should we consider it in the exam?
 
Ankit Garg
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am considering the exception object in GC count, the variable i is a primitive type so that doesn't count. In your example its sure that the code will throw an ArithmeticException that's why I've considered it in counting the number of objects eligible for GC...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic