- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
[OT] a simple garbage collection question
Mon, 2010-03-15, 16:57
hi,
this is a bit OT as it's a generic java VM question i guess.... but maybe someone smart can answer it quickly.
if i have this
class Test {
private val anoObject = new AnyRef
}
val x = new Test
is anoObject threatened to be garbage collected while i still have references to x? i.e. does the VM "know" that anoObject is unreachable? do i need to make it's scope 'protected' to save it from garbage collection?
thanks, -sciss-
Mon, 2010-03-15, 17:27
#2
Re: [OT] a simple garbage collection question
thanks!
Am 15.03.2010 um 16:00 schrieb David Pollak:
>
>
> On Mon, Mar 15, 2010 at 7:57 AM, Sciss wrote:
> hi,
>
> this is a bit OT as it's a generic java VM question i guess.... but maybe someone smart can answer it quickly.
>
> if i have this
>
> class Test {
> private val anoObject = new AnyRef
> }
>
> val x = new Test
>
> is anoObject threatened to be garbage collected while i still have references to x?
>
> No. Because x references anoObject, as long as there's a reference to x or anoObject, anoObject will not be GCed.
>
> i.e. does the VM "know" that anoObject is unreachable? do i need to make it's scope 'protected' to save it from garbage collection?
>
> thanks, -sciss-
>
>
>
>
On Mon, Mar 15, 2010 at 7:57 AM, Sciss <contact@sciss.de> wrote:
No. Because x references anoObject, as long as there's a reference to x or anoObject, anoObject will not be GCed.
--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Surf the harmonics