Fixed memory leaks associated with training and real-time segmentation.