FAQ for General stuff in CS193J

Last modified: July 9, 2002 12:15:08 PM PDT

  • What's the difference between calling arrayname.length ...
  • Why doesn't the Garbage collector always run immediately when ...

    Back to the CS193J Homepage




    Q:

    What's the difference between calling arrayname.length vs arrayname.getLength()?

    A:

    For an array, you have to use arrayname.length. There is no method you can message an array with to return it's length - rather it's stored as a public variable that you can
    Back to top...


    Q:

    Why doesn't the Garbage collector always run immediately when I make a System.gc call?

    A:

    First, remember that the garbage collector works automatically, whether you request it to or not. As it turns out, you cannot force the garbage collector to run. However, you can request the garbage collector to perform work, by invoking the System.gc() method. This request may be processed by the VM immediately, but it may not. Once working, you may experience a short pause while the garbage collector does its work. That means that if you want to manually run the garbage collector for some reason, you should do it at an appropriate time, such as before a big task or when the GUI is idle and waiting for input.
    Back to top...