You don't show where you delete myList in your code. You should delete in init's counterpart (cleanup?) or your MyClass destructor so that you don't leak memory for the list itself. I would add the following code to do that:
myList.clear(); // done by destructor, but doesn't hurt to clear IMHO
delete myList;
myList = nullptr;
myList.clear(); // done by destructor, but doesn't hurt to clear IMHO
delete myList;
myList = nullptr;
To copy to clipboard, switch view to plain text mode
Since you are not storing pointers to objects in your list, I don't see any issues with your handling of MyObjectData.
P.S. You will crash if your myList is empty when you run this code, so also check that myList->size() > 0 in your if statement.
Bookmarks