How to reduce phantomjs memory consumption? - webkit

I'm using phantomjs with casperjs to run multiple tests and it looks like each instance of PhantomJS takes ~106M of RAM. Is it possible to reduce that amount? Is there a simple way to run tests in multiple "tabs"?

Edit: As pointed by #newfurniturey, release is now deprecated. We must use close:
http://phantomjs.org/api/webpage/method/close.html
Don't know if that helps, but the release function could be a good tail :
http://phantomjs.org/api/webpage/method/release.html
Releases memory heap associated with this page. Do not use the page
instance after calling this.
Due to some technical limitation, the web page object might not be
completely garbage collected. This is often encountered when the same
object is used over and over again. Calling this function may stop the increasing heap allocation.
:)

Related

How to deal with phantomJS coredump?

Earlier, phantomJS core-dumped during a URL request
and related processing. (My shell does not capture core,
so I can't tell you what happened.)
I presume this is a bug in phantomJS. But more generally,
what is the recommended best practice for handling fatal
behavior in phantomJS? Does the process just return non-zero
if it fails?
Thanks.
PhantomJs has lots of little problems, crashing may be because it's out of memory (even if you have free pagefile space) or because you use it too many times without restarting, or if you try loading in resources it doesn't process properly (like .otf webfonts) or if there's an error in your script, or if you try rendering an image that's too big, or.... well, you get the picture.
The best way to troubleshoot this is to use console.write() statements in your script (everywhere, including in all the WebPage callbacks) and use this to narrow down where the crash is occurring.
The troubleshooting technique is rather crude, but I used this to great effect in my own usages of PhantomJs.

Does Println() use memory in live app?

In other words, should a production app eliminate all logging and printing to the console to reduce memory usage (or is the memory usage negligible)?
In general logging take some very small amount of device resources but it is so small that you shouldn't feel any changes unless you are printing a whole book to console ;)
Despite of this, I would recommend to remove all your logs if they are not provide any valuable information to user. Pure debug logs could be very annoying and if someone will work with your code in future, he can call you unprofessional ;)
I will recommend removing logs in methods which are called frequently due to the nature of the app (e.g. an update method in a game loop). In such methods one println may cause noticeable stuttering.
You can use a method for logging which will print only in debug (scheme-wise) and do nothing on a release scheme.
You could keep your logs in debug builds, but you better disable them completely, there have been some apps that printed passwords, tokens to the log, which isn't the best thing to do,

GHUnit gives allocate_pages() error after conversion to ARC in iOS Project

I've recently converted my iOS project to ARC. I have two targets in my project. One is the application itself, and the other is a set of GHUnit tests. I have approximately 200 tests that do quite a lot of work in terms of creating and modifying Core Data objects. The Core Data store used by the tests is an in memory store, and is thrown away once the tests are finished (i.e. it is not persisted anywhere).
When my tests have been running a while (they never reach the exact same point before the error is thrown, but it is always around the same tests) the application crashes with an EXC_BAD_ACCESS (Code=2, address=...)
The output in the console is as follows:
I've followed the instructions here in this answer, and set my main.m file of the GHUnit target to use the -fno-objc-arc compiler flag, but that doesn't seem to have helped.
I don't really understand what these errors mean, and searching for them doesn't seem to have helped. My only guess is that I am running out of memory, but I'm not sure why or how, considering ARC should be releasing objects for me.
I'd really appreciate any help anyone can give me to fix this! If you have any questions just leave me a comment and I will get back to you asap!
Thanks!
Chris,
First, As you have a memory exhaustion problem, you should look at your tests running under the Instruments allocation tool. Remember to turn on VM automatic snapshots. Then you should mark the heap multiple times as the tests execute.
Second, while this may be related to ARC, it quite possibly isn't. In general, ARC apps, because they can automatically release objects sooner, have a smaller footprint than MRR apps. The move to a new compiler with different options may just be uncovering a pre-existing problem.
Third, because you are using an in-memory database, my first test would be to just change it to a SQLite DB. It can have a much smaller footprint. (While you may choose to return to in-memory DBs later, we're trying to find the cause of your memory exhaustion. An in-memory DB can use a lot of RAM. Hence, lets take is out of the equation.
Once you've done the 1st and 3rd tasks above, please report back your results.
Andrew

Launch VB.NET form as a separate process

I have VB.NET application in which one of the form has IE control in it, the application starts initially with memory size consumed around 9 MBs, but when IE form is launched, the memory consumed rises to 27 MB, and when that form is closed, the memory reduces merely by 3-4 MBs, so why memory allocated to IEFrame is not de-allocated automatically? is there any work around to solve this issue? if possible, launching the form as a separate process would be helpful.
If you make sure to dispose the form properly, the garbage collector should free up that memory eventually. Running the IE control in a separate process should not be necessary.
However, if you are using IE 7, you might want to read this question about memory leaks.
Why not just put that form in a separate application if this is an issue? There are plenty of ways you can pass whatever data between the two apps.
The still allocated memory might not be an issue at all. If you have sufficient available memory in the computer the .NET Garbage Collector will not run to clean up. Only when you need the memory the GC will kick in.
If you want to make sure it is a leak you could do the following:
Make sure you have no references to the form in any way.
Call GC.Collect()
See if the memory is still claimed
Do not put the GC.Collect() in the final build; it's just to make sure you are not hunting ghosts.

Measure heap memory used by individual objects

Just curious, Is there a way to measure the heap memory consumed by each individual object from inside the code in realtime?
(I know I can use VisualVM and Eclipse Memory Analyzer as answered here, but is there a way to do this from the inside?)
Since you don't want to you the free tools available, you can look into the Hprof (freely available)code, try to change it in your own way. Hprof internally uses JVMTI . It will work.