Re: about static variable




"George2 via JavaKB.com" <u14844@uwe> schrieb im Newsbeitrag
news:56a3fd504a8ab@xxxxxx
> Hello everyone,
>
>
> I have heard that static variable will make the program consume very much
> memory. It is because garbage collector (GC) will not work on static
> variable.
> Is that correct?

A static variable is a class variable and therefore will reside in memory
even when no object of that class type exists. It does not consume very much
memory unless you load a lot of classes with big static arrays and don't
instantiate them.

If you have an instance (an object), it doesn't really matter if the
variable is static or not, it will be on the heap anyway. If you have a lot
of instances of the same class type, then you save memory by declaring the
variable static (you will have only one, instead of one for every instance).

BUT: the decision static or not should be made considering OO-Design choices
rather than memory problems.

> I am also wondering when does the memory space of a static variable is
> allocated, during compile or during runtime?

Of course the memory is allocated when starting the program. Compiling has
nothing to do with program execution.

andreas


.



Relevant Pages

  • about static variable
    ... I have heard that static variable will make the program consume very much ... It is because garbage collector will not work on static variable. ... I am also wondering when does the memory space of a static variable is ... Prev by Date: ...
    (comp.lang.java.help)
  • Re: Print statement within If-Then block changes output!!!????
    ... assembler/compiler into producing it. ... ordinary variable because all of them are BCD floating point. ... POKE a value into memory, ... It sounds like they're supposed to compile. ...
    (comp.lang.fortran)
  • Re: Dual Core or Quad Core when running Quartus 7.1
    ... You're right about the importance of memory sub-system performance -- ... You have to tell Quartus that you want it to use more than one ... that compile time ...
    (comp.arch.fpga)
  • Re: 7.0 CPU and Memory Performance
    ... Since I was doing this on the same machine, with completely different builds (not simply a compile upgrade, but a full install), I figure it doesn't really matter what kind of machine it is, but just for grins, it is a Dual Opteron with 2GB of memory in it, compiled with the i386 confs. ... Now, I really don't know exactly what the ubench program is doing, but I think the description says that it is doing random integer and floating point operations for the CPU tests, and random memory allocation and copying for the memory test. ... I tried to run a PHP script using php 4.4.7 and got the following results: ... do the slower memory operations cause that difference in the real time it takes to run that script??? ...
    (freebsd-performance)
  • Re: Java and memory usage
    ... wasn't a large enough heap) and it then only used 10MB of memory. ... BTW do you mean you assigned the memory at compile time or runtime? ... It is running as a pathway server and I feed it the following ...
    (comp.sys.tandem)