ij-legacy: collect only weak ImagePlus references in legacy mode

While in legacy mode, we need to make sure that we collect the images
opened so that we can add them to the modern state when turning off
legacy mode.

However, we did that by collecting the ImagePlus references directly
which leads to problems when said images are closed *before* switching
off the legacy mode.

So let's just switch to using weak references to the images instead;
that way the garbage collector can release memory no longer in use
(but we have to be careful to test whether the references we collected
are still valid before using them).

Hopefully, this fixes the memory issue reported by Olivier Burri.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Merge branch 'fix-legacy-mode-oom'

This branch intends to address the issues reported by Olivier Burri in

	http://thread.gmane.org/gmane.comp.java.imagej/29427

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>