ram

A Java method to log Android memory use

As a quick note today, here’s a little Java method that I use to log Android memory use (RAM use) from an Activity or Fragment:

private void logMemoryInfo(Context context, String TAG) {
   ActivityManager activityManager = (ActivityManager) context.getSystemService(getActivity().ACTIVITY_SERVICE);
   int memoryClass = activityManager.getMemoryClass();
   ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
   activityManager.getMemoryInfo(memoryInfo);

   Log.i(TAG, "\n------------ RAM -------------");
   Log.i(TAG, "mem class: " + memoryClass);
   Log.i(TAG, "mem avail: " + memoryInfo.availMem);
   Log.i(TAG, "low mem:   " + memoryInfo.lowMemory);
   Log.i(TAG, "threshold: " + memoryInfo.threshold);

   long mb = 1024*1024;
   Runtime runtime = Runtime.getRuntime();
   Log.i(TAG, "Used Memory:  " + (runtime.totalMemory() - runtime.freeMemory()) / mb);
   Log.i(TAG, "Free Memory:  " + runtime.freeMemory()  / mb);
   Log.i(TAG, "Total Memory: " + runtime.totalMemory() / mb);
   Log.i(TAG, "Max Memory:   " + runtime.maxMemory()   / mb);
}

This website is a little one-man operation. If you found this information helpful, I’d appreciate it if you would share it.

Using the Client JVM and controlling RAM when building a Scala/Java/Mac application

For my TypewriterFX application (which plays Mac OS X typewriter sound effects), I wanted/needed to control the JVM that was used to run the application. The way it works, TypewriterFX plays sounds as fast as it can -- as fast as you type -- so I needed the JVM to be more like the old client JVM than a typical server JVM.

This website is a little one-man operation. If you found this information helpful, I’d appreciate it if you would share it.

How to show memory usage in a running Scala application

You can show used, free, total, and max memory (RAM) available in a Scala application just like you do in Java. The lines of code look like this:

This website is a little one-man operation. If you found this information helpful, I’d appreciate it if you would share it.

How to set Java/JVM command line arguments when running a Scala application

To set Java/JVM command line arguments when running a Scala application with the scala command, set the JAVA_OPTS environment variable before running your application, something like this:

$ JAVA_OPTS="-Xmx256m -Xms64m -Xss16M"

$ scala my_scala_app.jar

I found this information on this scala man page document, where they also state this about the JAVA_OPTS variable:

This website is a little one-man operation. If you found this information helpful, I’d appreciate it if you would share it.

Scala REPL: java.lang.OutOfMemoryError: Java heap space error

I just got a “java.lang.OutOfMemoryError: Java heap space error” when trying to use the Scala REPL to analyze a large XML dataset, as shown here:

This website is a little one-man operation. If you found this information helpful, I’d appreciate it if you would share it.

Linux: How to get CPU and memory information

Linux FAQ: How can I find Linux processor and memory information? (Also written as, How can I find Linux CPU information?, How can I find Linux RAM information?)

To see what type of processor/CPU your computer system has, use this Linux processor command:

cat /proc/cpuinfo

As you can see, all you have to do is use the Linux cat command on a special file on your Linux system. (See below for sample processor output.)

To see your Linux memory information and memory stats use this command:

This website is a little one-man operation. If you found this information helpful, I’d appreciate it if you would share it.

The Drupal Diaries, Day 12

If you're interested in the really short story, this Drupal-based website is now hosted on a new, dedicated Linux server with much more RAM than the old server. For the longer story -- and the details of Apache tweaks and a script to automatically restart Apache when it got hung up -- read on.

Surprised by the Drupal plus LAMP memory use

I ended up being really surprised, but it turns out that Drupal and the LAMP architecture (Linux, Apache, MySQL, and PHP) take much more memory than the old Java-based blog that I had running the DevDaily site previously.

This website is a little one-man operation. If you found this information helpful, I’d appreciate it if you would share it.