I am a newbie just started exploring Grails so that I can recommend this
great framework for projects at our work. While learning I am trying to
create a prototype of the application using Grails 1.3.7 on ubuntu,

when I run-app after few minutes my system hangs and the system monitor
shows that it consumed more than a gig of memory. I am only running a
browser and terminal and not even netbeans or eclipse.

I thought that it might be because of in memory hsql db, but I configured
mysql and even then its the same memory issues. My application is very
simple couple of forms and I am using spring security,jms and searchable
plugin and nothing more.

I would really appreciate any suggestion which would improve the memory
issue or else I will have to pass off this framework. Being a developer I
feel sad that I am going to miss out such wonderful framework just because
of on such issue.

My computer has 2 gig of RAM and only runs a chrome browser and terminal. Also I only have only one controller I made and couple of domains thats all.

Please provide step by step instructions to improve as I am totally new to this

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
If this question can be reworded to fit the rules in the help center, please edit the question.

You do not have -Xms set to a high value by accident? If not something else must be going. While Grails does have rather high memory requirements this is more in the range of 128mb-256mb for a very simple application.
–
RubenMay 25 '11 at 6:17

Just wanted to chime in that I have the same issue: when I launch my Grails app (less than a dozen controllers and domain classes, scaffolded) but then do absolutely nothing but leave it running, jvisualvm shows continuously climbing heap usage. Note: I'm not even hitting the app yet (no requests yet), just launching.
–
AlistairIsraelNov 9 '11 at 2:59

I had some issues with Grails and high memory usage last year when I deployed my first big grails application to production. My application does a lot of database selects, inserts, deletes and updates and executes around 10000 of them per minute with around 100 active sessions/users.

For development I did fine with 1024M HEAP. However when deployed to production memory usage increased a lot. I got OutOfMEmory exception in minutes. The first thing I did was increasing the HEAP size to 2048M and the application would now run for a week before throwing an OutOfMemoryError exception again. I also used the -XX:+UseConcMarkSweepGC Garbage collector.

I guessed there was a memory leak somewere, but I couldn't figure it out. So I installed the
Java Melody plugin to monitor memory usage. I also used JVisualVM to find out what type of object that could be eating all the memory.

After some days of monitoring it turned out that there are no memory leaks, however there was some moments of spikes were the memory usage went through the roof. Average memory usage at this time was around 1200MB. I increased the HEAP again to 3072M and now the spikes would never use more HEAP than available, but the spikes could use up to 2800MB of memory.

My application was now stable, and would run for months without any problems. However memory usage was still high and I've done some work over the months to improve this. There was two things that really helped to decrease memory usage.

The first one was easy, disable hibernate secondary cache. This is known to be helpful if you have data that changes frequently. For me this also slightly improved overall performance. This can be done in grails-app/conf/DataSource.conf

cache.use_second_level_cache=false
cache.use_query_cache=false

The second thing I did was tuning the Searchable plugin. I started with returning one thousand hits, now max hits is hundred.

Those two adjustments reduced the spikes about 75%. I've also done a lot of minor adjustments related to queries, especially reducing the amount of data a query returns.
For example I have a domain class named Issue with over 20 properties, but I only need a few of the properties when rendering to a view. It is possible to convert the results to a map like this:

Issue.executeQuery(
"select new map(i.id as id, i.title as title i.date as date) FROM Issue i"
)

Adjustments like this can improve query time, memory usage and overall performance. Hope it helps.

Don't know what you did exactly but I almost be certain that you mess something in application. How can I be sure? Well, I run Ubuntu 11.04 with 2G memory, with STS, Chrome and Firefox at same time. Even when I switch DB from hsql to mySql ( that means I need to start mySql ) I do not have issues you have. And application I'm working on is not for testing Grails. So, before you spend some money I suggest you write some tests, do some code inspection or even profiling. I bet you find something that is fishy and you'll get some good exercise.

code is not at all complicated stuff, i am trying to build a twitter clone to learn the language. and only one user is hitting the system. still fail to understand the memory consumption. I would really appreciate if you could help me out any tips/tricks you might have used apart from simply upgrading your RAM.
–
srisrisMay 25 '11 at 7:24

Grails being a Java based framework built on top of Spring and Hibernate you have to understand that there is going to be some memory consumption. Especially in development mode. Not to mention all the in memory wiring/caching that takes place for lucene (the searchable plugin). A gig is nothing. Buy more ram. It is cheap.

My development machine has 8 gigs of ram. I'd never work with any less than that.

Please provide step by step
instructions to improve as I am
totally new to this