Patch to huge memory consumption in LO Calc

Stephan Bergmann sbergman at redhat.com
Mon May 26 02:20:06 PDT 2014


On 05/24/2014 02:47 PM, William Bonnet wrote:
> Even if it may look like a memory leak, it is not really one since the
> memory will be released after the document is closed. The problem exist
> on recent versions of LO, including master.

("Space leak" is jargon for such symptoms, cf. 
<http://queue.acm.org/detail.cfm?id=2538488> "Leaking Space.")

> --- multi_type_vector_types.hpp.orig	2014-05-24 13:53:09.482797120 +0200
> +++ multi_type_vector_types.hpp	2014-05-24 13:55:39.049154637 +0200
> @@ -249,6 +249,12 @@
>      static void resize_block(base_element_block& blk, size_t new_size)
>      {
>          static_cast<_Self&>(blk).m_array.resize(new_size);
> +        // Test if the vector have allocated capacity (thus memory) superior to
> +        // twice its current size. If yes thus, shrink its memory footprint
> +        // Vector from STL does not free its memory when its downsized
> +        if (static_cast<_Self&>(blk).m_array.capacity() > (2 * new_size)) {

This should probably use "/2" instead of "*2" to avoid overflow.

> +            static_cast<_Self&>(blk).m_array.shrink_to_fit();

Two problems with std::vector's shrink_to_fit are that it is a C++11 
addition and that it is merely a non-binding request to reduce capacity.

Stephan


More information about the LibreOffice mailing list