# std::ostrstream::~ostrstream

> C++ Atlas: `cppatlas.com/w/cpp/io/ostrstream/~ostrstream` | Source: https://en.cppreference.com/w/cpp/io/ostrstream/~ostrstream | Domain: Input/output | Standards: C++26

Destroys a std::ostrstream object, which also destroys the member std::strstreambuf, which may call the deallocation function if the underlying buffer was dynamically-allocated and not frozen.

## Official Specification Summary (cppreference)

```cpp
virtual ~ostrstream(); // (deprecated in C++98) (removed in C++26)
```

Destroys a `std::ostrstream` object, which also destroys the member `std::strstreambuf`, which may call the deallocation function if the underlying buffer was dynamically-allocated and not frozen.

### Parameters

(none)

### Notes

If `str()` was called on a dynamic `ostrstream` and `freeze(false)` was not called after that, this destructor leaks memory.

### Example

```cpp
#include <iostream>
#include <strstream>

int main()
{
    {
        std::ostrstream s; // dynamic buffer
        s << 1.23;
        std::cout << s.str() << '\n';
        s.freeze(false);
    } // destructor called, buffer deallocated

    {
        std::ostrstream s;
        s << 1.23;
        std::cout << s.str() << '\n';
//      buf.freeze(false);
    } // destructor called, memory leaked
}
```

Output:

```text
1.23
1.23
```

---
Attribution: content from https://en.cppreference.com/w/cpp/io/ostrstream/~ostrstream (cppreference.com), licensed under CC-BY-SA 3.0 and GFDL. Modified: converted to markdown, study notes added. Offline snapshot of 9 February 2025.