Code:
for (int i = 0; i < random_num; i++)
{
TEST2 *temp = new TEST2(param1, param2, param3);
test2_list.push_back(*temp);
}
You're apparently not aware of what this code does. You allocate memory for a TEST2 object and initialize it. Then, you put a copy of that object into the vector. The vector automatically allocates memory to hold it. Then you start the next iteration, thus losing the pointer to the memory you just allocated and creating an irrecoverable memory leak.
Since the way you have it now is "working", you probably want this:
Code:
test2_list.reserve(random_num); // This line makes the loop faster.
for (int i = 0; i < random_num; i++)
{
test2_list.push_back(TEST2(param1, param2, param3));
}
In that case, you don't need to worry about the memory anymore. When the vector is destructed, the associated memory gets freed.