Eclipse LaunchConfigurationDelegate prone to memory leaks

LaunchConfigurationDelegates in Eclipse remain in memory after their launch method has executed. As such, they also prevent any object they reference from being garbage-collected. For example in the following code

class MyLaunchConfigurationDelegate extends LaunchConfigurationDelegate {

    protected BigObject bigObject = null;

    public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor progressMonitor) throws CoreException {
        this.bigObject = createBigObject();		
    }
}

bigObject will remain in memory for ever, so it’s worth keeping this in mind and cleaning up before returning from launch().

Mac OS X Lion + Subclipse 1.8.x = Incompatible JavaHL library loaded. 1.7.x or later required.

The problem appears to be that Subclipse 1.8.x needs Subversion 1.7 to run. Installing Subversion 1.7 from http://www.wandisco.com/get/?f=subversion-binaries/1.7/Subversion-1.7.2_10.7.x.pkg gets everything to work like a charm once again (a complete list of downloads is available here: http://www.ubersvn.com/download)

Subclipse forgetting SVN password on Mac OS X

Sometimes, Subclipse can forget your password for certain SVN repositories and although you select “Save password” in the authentication dialog, it will keep asking for it every single time. It’s probably an overkill, but to solve this, I’ve had to clear the SVN credentials cache (warning: this will make SVN forget all passwords for all repositories) as follows:

  1. Close Eclipse
  2. Open Terminal
  3. Type defaults write com.apple.Finder AppleShowAllFiles YES
  4. This will make hidden files visible
  5. Go to /Users/your-user-name/.subversion in Finder
  6. Delete the auth directory under it
  7. Start Eclipse

 

How to convert SVG to PDF on a Mac

The fastest way I’ve found to convert an SVG image to PDF so that I can use it in LaTeX on my Mac is the following:

  1. Use this online conversion tool to convert the SVG to an A4-size PDF: http://www.fileformat.info/convert/image/svg2pdf.htm
  2. Download the produced PDF and crop it using Preview

Supposedly, Incscape can do the conversion in one step but it takes about 3 centuries to start on my Mac and it didn’t render a couple of SVGs I tried it with correctly.

How to get all Mac OS X window titles from Java

The following getOSWindowTitles() method returns a list of the titles of all open windows in Mac OS X (requires Java 6 and you’ll also need to tick the “Enable access for assistive devices” option in the Universal Access preference page)

public List<String> getOSWindowTitles() throws ScriptException {
    List<String> osWindowTitles = new ArrayList<String>();
    String script = "tell application \"System Events\" to get " + 
        "the title of every window of every process";

    ScriptEngineManager mgr = new ScriptEngineManager();
    ScriptEngine engine = mgr.getEngineByName("AppleScript");
    ArrayList<Object> results = (ArrayList<Object>) engine.eval(script);
    
    for (Object result : flatten(results)) {
        if (result != null) osWindowTitles.add(result.toString());
    }
    
    return osWindowTitles;
}

public List<Object> flatten(Collection<Object> nested) {
    ArrayList<Object> flat = new ArrayList<Object>();
    for (Object o : nested) {
        if (o instanceof Collection) {
            flat.addAll(flatten((Collection) o));
        }
        else {
            flat.add(o);
        }
    }
    return flat;
}