GithubHelp home page GithubHelp logo

Comments (5)

mclow avatar mclow commented on June 21, 2024

I'm not seeing a memory leak here. What is getMemoryUsage, and what system are you running this on?
My test program (attached) reports that every allocation is paired with a deallocation. (Boost trunk, on Mac OS 10.14)

#include <vector>
#include <iostream>
#include <cstdio>

#include <boost/dynamic_bitset.hpp>

void* operator new (std::size_t count)
{
    void *ptr = malloc(count);
    ::printf ("Allocating %ld bytes at %p\n", count, ptr);
    
    return ptr;
}

void* operator new[]( std::size_t count)
{
    void *ptr = malloc(count);
    ::printf ("Allocating %ld bytes[] at %p\n", count, ptr);
    
    return ptr;
}

void operator delete(void *ptr) throw()
{
    ::printf ("deleting %p\n", ptr);
	free(ptr);
}

void operator delete[](void *ptr) throw()
{
    ::printf ("deleting[] %p\n", ptr);
    free(ptr);
}


int main() {
	{
	std::vector<boost::dynamic_bitset<>> m_nodes;
// 	m_nodes.resize(1000000 + 1);
	m_nodes.resize(10 + 1);
	uint64_t descriptor[4] = {1, 2, 3, 4};
	for(size_t i = 0; i < m_nodes.size(); i++)
		{
		m_nodes[i] = boost::dynamic_bitset<>(descriptor, descriptor + 4);
		}
	::printf("Exiting scope\n");
	}
}

from dynamic_bitset.

robot-kimbo avatar robot-kimbo commented on June 21, 2024

Hi, thanks for reply.

  1. system: ubuntu 18.04, boost 1.66.0 release version, gcc/g++ -7
  2. getMemoryUsage() is code of get the program memory, it like command "busybox top"
    here is the linux code of it:
    unsigned long getMemoryUsage()
    {
    unsigned long MEM = 0;
    FILE *f = ::fopen ("/proc/self/stat", "r");
    if (!f) return 0;
    if (!::fscanf(f,
    "%*d %*s %*c %*d %*d %*d %*d %*d%*u %*u %*u %*u %*u %*u %*u%*d %*d %*d %*d %*d %*d %*u %lu", &MEM))
    {
    // Error parsing:
    MEM=0;
    }
    ::fclose (f);
    return MEM/1024/1024;
    }
  3. For my test program, you can see after destruct of "std::vector<boost::dynamic_bitset<>>", the memory can not restore "13M", that why I mean "std::vector<boost::dynamic_bitset<>>" has memory leak.

from dynamic_bitset.

robot-kimbo avatar robot-kimbo commented on June 21, 2024

Hi, I also test std::bitset, the memory of this has not meomory leak, here is the test program

int main()
{
cout << "[ memory start ] " << getMemoryUsage() << std::endl;
{

    std::vector<std::bitset <256> > m_nodes;
    m_nodes.resize(1000000 + 1);
    uint64_t descriptor[4] = {1, 2, 3, 4};
    std::bitset <256> tmp(ULONG_MAX);
    for(size_t i = 0; i < m_nodes.size(); i++)
    {
        m_nodes[i] = tmp;
    }
}
cout << "[ memory end ] "  << getMemoryUsage() << endl;

}

The result is:
[ memory start ] 13
[ memory end ] 13

from dynamic_bitset.

swatanabe avatar swatanabe commented on June 21, 2024

from dynamic_bitset.

robot-kimbo avatar robot-kimbo commented on June 21, 2024

Ok, got it, thank you very much.

from dynamic_bitset.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.