Fix for a crash caused by deleting linked counts, also an attempt to
catch out of memory crashes for big images.