Question: I just found out that you can do this in C++:

```
class Line
{
public:
    Line(int x) : _length(x) {}
    int GetLength() { return _length; }
private:
    int _length;
};

int main()
{
    Line* line = new Line(3); // instead of doing this
    std::cout << line->GetLength();

    std::cout << (new Line(5))->GetLength(); // you can instantiate the object directly without storing it in a pointer
}

```

Now my question is, after that last line of code, does the object with length=5 get deleted immediately in the heap? If not, how do we delete it since we can't use

```
delete line;

```

like in the first object with length=3.

Answer: 
The object doesn't get deleted: there is no corresponding call to `delete` for the call to `new` it was allocated with. Do assign it to a pointe then delete that and avoid a memory leak.

Better alternatives:

* just use the stack: `Line(5).GetLength()` will call Line's destructor and free any memory allocated (on the stack) automatically after that line since the temporary unnamed object goes out of scope.
* use `std::make_unique<Line>(5)->GetLength()`. Under the hood this does allocate a `new` Line on the heap. Aterwards, same story: when the unique\_ptr this creates goes out of scope it's destructor is called and that will in turn call the corresponding `delete`.
Congratulation on discovering the concept of a "memory leak".

The next step on your adventure is to learn all about [`std::unique_ptr`](http://en.cppreference.com/w/cpp/memory/unique_ptr), [`std::shared_ptr`](http://en.cppreference.com/w/cpp/memory/shared_ptr), [`std::make_unique`](http://en.cppreference.com/w/cpp/memory/unique_ptr/make_unique), and [`std::make_shared`](http://en.cppreference.com/w/cpp/memory/shared_ptr/make_shared), which will allow you to do pretty much the same thing, but without leaking memory all over the place.

And, as an extra bonus, you don't have to worry about `delete`ing anything, ever again.