Working listView and memory management.

Now it deletes everything in memory correctly. Hopefully there are no
memory leaks.