I keep getting a Memory Leak which seems to occur because the new initialized objects passed as pointers to `add(…)` are not actually `delete`. But somehow, I cannot make this work properly. I tried adding a `for`-loop to loop every object in array within class Monsters to `delete` each object when the call of the `destructor` is invoked. And then to do `delete[] monsters;` and `monsters = nullptr`.

<https://repl.it/@xxxxxx10/TatteredTroubledTasks>

---

```
#include <iostream>
#include <string>

class Monster{
public:
  Monster(){};
  Monster(std::string name) : name(name){}
private:
  std::string name = "";
};

class MonstersList {
public:
  MonstersList(int max):max(max){
    monsters = new Monster[max];
  }

  virtual ~MonstersList() {
      delete[] monsters;
  }

  void add(const Monster* m){
    monsters[total++] = *m;
  }

 Monster* begin() const { return monsters; }
 Monster* end() const { return monsters + total; }

private:
  Monster* monsters = nullptr;
  int max = 0;
  int total = 0;
};

MonstersList* InitListOfMonsters()
{
    MonstersList* monsters = new MonstersList(2);
    monsters->add(new Monster("Sally"));
    monsters->add(new Monster("Rich"));

    return monsters;
}

int main()
{
  MonstersList* monsters = InitListOfMonsters();

  // Do something here...

  return 0;
} // <----- Memory leak!

```

How can this be prevented from happening, recall, I tried to for loop and delete each monster pointer object in the array.

**EDIT:** When I try for-loop to delete each object, then an error sort of occurs, breaks at `delete_scalar.cpp` <-- Microsoft C++ file.

```
_CRT_SECURITYCRITICAL_ATTRIBUTE
void __CRTDECL operator delete(void* const block) noexcept
{
    #ifdef _DEBUG
    _free_dbg(block, _UNKNOWN_BLOCK);
    #else
    free(block);
    #endif
}

```

Occurs when I run this code in `destructor`:

```
if (monsters != nullptr) {
    for (Monster* m = begin(); m != end(); m++) {
        delete m;
    }

    delete[] monsters;
    monsters = nullptr;
}

```