Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Critical memory leak with J/Link

  • To: mathgroup at
  • Subject: [mg47558] Re: [mg47530] Critical memory leak with J/Link
  • From: "Werner Schuster" <werner.schuster at>
  • Date: Fri, 16 Apr 2004 05:20:23 -0400 (EDT)
  • References: <>
  • Sender: owner-wri-mathgroup at

> Memory is not freed with calls to JavaGC[].  It is only freed with
> QuitJava[] or quitting the kernel.

You might want to refer to the "Reference Counts and Memory Management"
section of the J/Link Userguide;

JavaGC[] won't be of much help, if there is still a valid reference
to the Object; in your case, the "g" expression still points to the
MemoryHolder, which in turn still references the large Graph Expression
that you passed in. This is, as far as I see it, correct behaviour
 (Mathematica or J/Link doesn't know that you don't intend to use
the "g" expression/reference anymore, so it keeps it).

You can use either JavaBlock[] (wrap your code inside it) or one
of the Release* Expressions (ReleaseObject[],...) to get rid of the
reference (possibly followed by a JavaGC[] to make sure the GC frees the

I suppose that should solve your problem (unless I'm missing
something else).

Werner Schuster (murphee)
Student of SoftwareEngineering and KnowledgeManagement
Maintainer of the OGO-JOGI Project @
Blog @

  • Prev by Date: Re: Re: When Is Precision[ ] $MachinePrecision, And When Is It Not?
  • Next by Date: Re: Obtaining Standard Errors when using FindMinimum in Mathematica
  • Previous by thread: Critical memory leak with J/Link
  • Next by thread: Re: Critical memory leak with J/Link