Closing figure instance in waveform plotting.

The destructor now closes the most recently created figure instance in
case a figure instance was created during initialization. This enables
proper garbage collection for the figure. Fixes #512.