Fixed segmentation fault by modifying destructors and allowing SWIG to handle garbage collection