My app is constantly running out of memory. I am using a static instance of most Classes to perform operations that have no state, but I am worried that this is the cause of my memory leaks.
My tech stack is heroku/playframework 1.2.7/mongodb (compose.io)
The basic pattern I have is:
public class Product{
public productName;
public productDesc;
public productPrice;
private static final Product INSTANCE = new Product();
public static Product instance() {
return INSTANCE;
}
// an example (not actual) method is
public List<Product> listAllProducts(String brand, String category){
//not the actual DB code
Db.connect().find(Product.class).listAllItems(brand, category);
}
}
Which I use like this
List<Product> products = Product.instance().listAllProducts("hugo-boss", "jeans");
Is there something fundamentally wrong with this code that will cause memory leaks in a web app with a handful - but not a huge number of concurrent users?
Thanks for your help.
UPDATE
Doing heroku config:set _JAVA_OPTIONS="-Xms256m -Xmx384m -Xss512k -XX:+UseCompressedOops"
didnt' work for now.
I enabled one of the add-ons that gives memory info in the logs, here's what I'm getting:
2015-01-09T16:18:58.614435+00:00 heroku[web.3]: source=web.3 dyno=heroku.18312286.ad920471-c3dd-4d5d-a55b-28ea79905c14 sample#load_avg_1m=3.65
2015-01-09T16:18:58.614631+00:00 heroku[web.3]: source=web.3 dyno=heroku.18312286.ad920471-c3dd-4d5d-a55b-28ea79905c14 sample#memory_total=439.86MB sample#memory_rss=438.86MB sample#memory_cache=1.00MB sample#memory_swap=0.00MB sample#memory_pgpgin=138042pages sample#memory_pgpgout=25438pages
2015-01-09T16:19:10.683077+00:00 heroku[web.2]: source=web.2 dyno=heroku.18312286.910cbbef-7613-4daf-a856-230e08618cc7 sample#load_avg_1m=1.90 sample#load_avg_5m=0.86
2015-01-09T16:19:10.683364+00:00 heroku[web.2]: source=web.2 dyno=heroku.18312286.910cbbef-7613-4daf-a856-230e08618cc7 sample#memory_total=367.73MB sample#memory_rss=365.02MB sample#memory_cache=2.71MB sample#memory_swap=0.00MB sample#memory_pgpgin=141344pages sample#memory_pgpgout=47205pages