Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build a Simple Android App (2014) Improving Our Code Simple Refactoring: Using a Class

aybars tokta
aybars tokta
4,491 Points

Random object is created every time we push the button(in getFact method). So, doesn't it cause our app to stop finally?

Random object is created every time we push the button(in getFact method). So, doesn't it cause our app to stop finally?

1 Answer

Seth Kroger
Seth Kroger
56,414 Points

If by "finally stop" you mean continually creating new Random objects will cause the phone/tablet/etc. to run out of memory, it won't. Once the getFact() method exits, the object it created is no longer in use because it is only a local variable, and not stored in a member variable, other object or return value. Unused objects are periodically swept up by what is called the Garbage Collector to free them from memory.

aybars tokta
aybars tokta
4,491 Points

Thanks for the answer

aybars tokta
aybars tokta
4,491 Points

Thanks for the answer