В круге 360 градусов и 2 пи радиана. Таким образом, чтобы преобразовать градусы в радианы, разделите на 360 и умножьте на 2 * пи (прибл. 6.28).
Или, что то же самое, разделить на 180 и умножить на pi.
you can try to make it final, and recompile the code in order to see if some other class CHANGES the reference to null:
public class Global {
public final static List<String> data = new ArrayList<String>();
}
this allow to write:
Global.data.add("foo");
but not:
Global.data = null;
Исходный вопрос:
Когда выполняется сборка мусора происходит для статического класса?
Ответ: Когда ваше приложение завершает работу.
I have a few variables in a static class, which get written to... at several different points.
As you are confessing yourself, so a null can be assigned to the variable at one or more of those different points. :)
As Svetlio said, the GC only runs on objects on the heap which aren't referenced anywhere. This may take x number of cycles depending on which GC-strategy and VM you're using. Since static classes are indefinitely referenced, they'll never be GC'd.
So some issues remain:
new
on your static class at any time?Lasty, as you said...static variables suck for anything other than constants :P A singleton configuration is really cheap and a lot better.
If you can call the function than the object won't be garbage collected away because there's still a reference to it. Are you storing a pointer to the arraylist or the object itself?
Сборка мусора для классов происходит, если его загрузчик классов получает сборщик мусора. См., Например, этот вопрос . В более ранней версии Java (я думаю, в 1.2) было время сортировки, когда статические поля не учитывались сборщиком мусора, и большое количество выгрузки / перезагрузки классов приводило к пустым полям.
Static classes aren't like static variables. It's just yet another use for the keyword "static". In this case, it indicates the class is top-level but declared within another class.
So that means you can instantiate more than one object of this class, unlike say a static variable, for which there is only one copy.
Are you instantiating more than one of these and expecting them to be the same one?
The GC doesn't sound like it is the issue. If the object were no longer there, you couldn't retrieve the ArrayList from it at all.
Сборщик мусора не будет удалять статический класс сам по себе. Сборщик мусора может стать активным только в том случае, если нет ссылки на класс. Пока вы можете вызывать сам класс, ссылка есть. Also you cannot definitely say when the garbage collector is getting active. It runs as some kind if idle-task in the background.
I would recommend you to add some debug trace messages to your static class, so that you can see when it's called. There must be some side effects changing your ArrayList at runtime.
Статическое значение может быть нулевым, если оно находится в другом потоке. В противном случае он всегда должен быть там, если вы не скажете ему что-нибудь еще.