Make sure to destroy AndroidDrawDevice even upon exception.

If the user repeatedly pinch zoomed in/out on a page that uses
separation groups the app would easily run out of memory and be killed
by Android.

The repeated pinch zooms implies that the user aborts running the page
display list by setting a flag in the cookie. At this point the draw
device is likely to leave unbalanced separation groups pixmaps on the
draw device stack. This is detected in fz_draw_close_device() and
generates an exception that is translated to a java exception. Cleanup
of the device along with any unbalanced separation group pixmaps happens
in fz_draw_drop_device().

The application previously failed to ensure that
AndroidDrawDevice.destroy() was called if AndroidDrawDevice.close()
ended up throwing an exception.

That meant that the device object and resources such as the draw stack
and its unbalanced pixmaps languish until Android's JVM decides to clean
up unreferenced objects. When it finally did, it would end up calling
fz_draw_drop_device() which freed all resources. The problem is that the
user generates new rendering requests by pinch zooming before Android
decides to clean up all unreference objects, hence memory usage
increases until Android kills the process.

This commit ensures that AndroidDrawDevice.destroy() is called
regardless of whether any exceptions are thrown. Thereby making sure
that the draw device is freed along with its draw stack and referenced
resources. This fixes the out of memory issue.
1 file changed