Usenet.com

www.Usenet.com

Group Index

Comp Thread Archive from Usenet.com

<-- __Chronological__ --> <-- __Thread__ -->

Re: Remaining Memory



"Stephen Thomas" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> On Tue, 09 Sep 2003 14:35:55 -0700, Bill Dennis wrote:
>
> > I want to preempt getting an "Out of Memory" error.  Can I calculate the
> > amount of memory remaining using the following formula?
> >
> > long memoryRemaining = runTime.maxMemory() - runTime.totalMemory() +
> > runTime.freeMemory();
>
> In theory, yes.  In practise, the result may not be useful.  For
> some JVMs obtaining those quantities (particularly runTime.freeMemory())
> may be a far less trivial operation than it seems.  In a highly concurrent
> application, any result you get may be completely irrelevent by the
> time you get to act on it, as memory may be being churned while the
> value is being computed.

(snip more about System.gc())

Also, what about fragmentation?   Do most, or any, actually move allocated
regions around?   So even if enough was available it might not be available
for one allocation.

-- glen





<-- __Chronological__ --> <-- __Thread__ -->


Usenet.com



Please check out one of the premium Usenet Newsgroup Service Providers below for access to Usenet.