No, it is not that simple. Each layer contains its own pointer and memory buffer. The layers in the vector gets freed on exit but the one sent to the undo system is not in the vector then so freeing things in the vector doesn't cause any issues the first time around. The second time the vector is filled in the undo pointer starts pointing to the same memory as the vector layer though for some reason so yes they share memory in some way.