Memory Usage Tips and Tricks

I'm currently working on a custom plugin for myself and my co-workers.  I have a dependent language defined, tab panel setup to view of files of the specified type, and a configuration service (at the project) level which identifies all of the necessary files.  After the tab panel populates, my memory usage goes from 64M to 254M.  I'm thinking I have some sort of memory issue going on in my code.  What sort of tips for managing memory could you share related directly to how IDEA processes data?

Some things I'm doing in my panel:

Tree Structure:

root (invisible)

PsiDirectory instance

list of matching files

top level elements


There are at least 3 dozen directories with five files each and each file could have any number of top level elements.


If I'm not explaining myself very well, please let me know.

One other thing to note, is the memory usage drops back down to around 64M after a little while.  So, I'm sure objects are getting released, it's just a matter of when and can I control it better.

6 comments

Hello Brad,

One useful tip is not to hold references to PSI elements inside PSI files
from UI elements. Holding a PsiFile is essentially free, but if you hold
a reference to a lower-level element, it holds the entire parsed PSI tree,
which can be quite large (particularly for many files). A better alternative
is to use SmartPointerManager.createLazyPointer().

In general, the memory figures you provide are nothing out of ordinary, so
there may be no need to optimize anything.

I'm currently working on a custom plugin for myself and my co-workers.
I have a dependent language defined, tab panel setup to view of files
of the specified type, and a configuration service (at the project)
level which identifies all of the necessary files.  After the tab
panel populates, my memory usage goes from 64M to 254M.  I'm thinking
I have some sort of memory issue going on in my code.  What sort of
tips for managing memory could you share related directly to how IDEA
processes data?

Some things I'm doing in my panel:

Tree Structure:

root (invisible)
PsiDirectory instance
list of matching files
top level elements
There are at least 3 dozen directories with five files each and each
file could have any number of top level elements.

If I'm not explaining myself very well, please let me know.

One other thing to note, is the memory usage drops back down to around
64M after a little while.  So, I'm sure objects are getting released,
it's just a matter of when and can I control it better.

---
Original message URL:
http://www.jetbrains.net/devnet/message/5262697#5262697

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0

So should I be using this to store pointers to the elements in my node descriptors?  I've tried this will my custom PsiElement instances (which extends MetadataPsiElementBase) and it seems to have helped my memory usage, but I can't be sure.  Also, should I be using this to store references to PsiElement in PsiReference implementations?

0

Hello Brad,

So should I be using this to store pointers to the elements in my node
descriptors?  I've tried this will my custom PsiElement instances
(which extends MetadataPsiElementBase) and it seems to have helped my
memory usage, but I can't be sure. 


Yes, for node descriptors this is good.

Also, should I be using this to
store references to PsiElement in PsiReference implementations?


PsiReference instances are typically either very short-lived or tied closely
to the PsiElement in which they are contained. Because of that, there's no
need to use smart pointers there - a direct PsiElement reference is just
fine.

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0

What about memory usage with the Find Usages functionality when there are hundreds of usages, or more?

0

Hello Brad,

What about memory usage with the Find Usages functionality when there
are hundreds of usages, or more?


What about it? :) It's a core problem; we've made some fixes in the IDEA
9 release to reduce memory consumption in this case, but it's likely that
more optimizations are possible.

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0

I was wondering if there was something I could do in my own plugin to reduce memory consumption for Find Usages.  Would a custom search scope help out so there aren't as many files to parse?  Or, is that not the problem?

0

Please sign in to leave a comment.