Updated to assume that we are working with data structures in memory. Assuming that garbage collection will take care by deleting the data element inside accordingly