librelist archives

« back to archive

memory leak

memory leak

From:
giovani milanez
Date:
2014-10-20 @ 14:11
Hi, i realized that components with std::vector member leaks memory, why?
Example:

struct Test : entityx::Component<Test>
{
    Test() : vec_({0.1, 1.3, 1.6}){};

    std::vector<float> vec_;
};

int main()
{
    entityx::EntityX e;
    auto test = e.entities.create();
    test.assign<Test>();
}
 		 	   		  

Re: [entityx] memory leak

From:
giovani milanez
Date:
2014-10-21 @ 11:17
Alec, thanks for fixing it.
I've been using your library to develop my first game, its awesome. I had 
no idea where to start and its helping me a lot! 

Date: Tue, 21 Oct 2014 10:47:24 +1100
From: alec@swapoff.org
Subject: Re: [entityx] memory leak
To: entityx@librelist.com


                
                    Hi!
                
Yes, it appears there is. I’ve fixed it and added a test case.
I think this crept in during the move to pools :(
Thanks for finding it,Alec
                
                 
                On Tuesday, 21 October 2014 at 2:19 am, giovani milanez wrote:
                
                    


Compile the program:

struct Test : entityx::Component<Test>
{
    Test() : vec_({0.1, 1.3, 1.6}){};

    std::vector<float> vec_;
};

int main()
{
    entityx::EntityX e;
    auto test = e.entities.create();
    test.assign<Test>();
}

Run with valgrind (memory leak detector tool):
valgrind --leak-check=full YOUR_PROGRAM

Results:

giovani@brytec-giovani:~/workspace-luna/SpaceTD/Debug$ valgrind 
--leak-check=full ./SpaceTD
==15850== Memcheck, a memory error detector
==15850== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==15850== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==15850== Command: ./SpaceTD
==15850== 
==15850== 
==15850== HEAP SUMMARY:
==15850==     in use at exit: 12 bytes in 1 blocks
==15850==
    total heap usage: 17 allocs, 16 frees, 99,064 bytes allocated
==15850== 
==15850== 12 bytes in 1 blocks are definitely lost in loss record 1 of 1
==15850==    at 0x402BE94: operator new(unsigned int) (in 
/usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==15850==    by 0x804C33F: 
__gnu_cxx::new_allocator<float>::allocate(unsigned int, void const*) 
(new_allocator.h:104)
==15850==    by 0x804C1AB: std::_Vector_base<float, std::allocator<float> 
>::_M_allocate(unsigned int) (in 
/home/giovani/workspace-luna/SpaceTD/Debug/SpaceTD)
==15850==    by 0x804C0C7: std::_Vector_base<float, std::allocator<float> 
>::_M_create_storage(unsigned int) (stl_vector.h:181)
==15850==    by 0x804BD5E: std::_Vector_base<float, std::allocator<float> 
>::_Vector_base(unsigned int, std::allocator<float> const&) 
(stl_vector.h:136)
==15850==  
 ;
 ;  by 0x804B85B: std::vector<float, std::allocator<float> 
>::vector(std::vector<float, std::allocator<float> > const&) 
(stl_vector.h:312)
==15850==    by 0x809F694: Test::Test(std::vector<float, 
std::allocator<float> >&) (SpaceTD.cpp:14)
==15850==    by 0x809F79A: 
_ZN7entityx13EntityManager6assignI4TestIRSt6vectorIfSaIfEEEEENS_15ComponentHandleIT_EENS_6Entity2IdEDpOT0_
(Entity.h:520)
==15850==    by 0x809F70D: 
_ZN7entityx6Entity6assignI4TestIRSt6vectorIfSaIfEEEEENS_15ComponentHandleIT_EEDpOT0_
(Entity.h:823)
==15850==    by 0x809F590: main (SpaceTD.cpp:30)
==15850== 
==15850== LEAK SUMMARY:
==15850==    definitely lost: 12 bytes in 1 blocks
==15850==    indirectly lost: 0 bytes in 0 blocks
==15850==      possibly lost: 0 bytes in 0 blocks
==15850==    still reachable: 0 bytes i
 n 0 blocks
==15850==         suppressed: 0 bytes in 0 blocks
==15850== 
==15850== For counts of detected and suppressed errors, rerun with: -v
==15850== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

gcc version: g++ (Ubuntu 4.8.1-2ubuntu1~13.04) 4.8.1

Date: Mon, 20 Oct 2014 11:08:47 -0400
From: isra017@gmail.com
Subject: Re: [entityx] memory leak
To: entityx@librelist.com

What is the diagnostic that lead you to believe there is a memory leak?
On Mon, Oct 20, 2014 at 10:11 AM, giovani milanez 
<giovani_milanez@hotmail.com> wrote:



Hi, i realized that components with std::vector member leaks memory, why?
Example:

struct Test : entityx::Component<Test>
{
    Test() : vec_({0.1, 1.3, 1.6}){};

    std::vector<float> vec_;
};

int main()
{
    entityx::EntityX e;
    auto test = e.entities.create();
    test.assign<Test>();
}
 		 	   		  

 		 	   		  

                 
                 
                 
                 
                
                 
                
                    

                 		 	   		  

Re: [entityx] memory leak

From:
Alec Thomas
Date:
2014-10-21 @ 12:47
Glad you're finding it useful!



> On Oct 21, 2014, at 10:17 PM, giovani milanez 
<giovani_milanez@hotmail.com> wrote:
> 
> Alec, thanks for fixing it.
> I've been using your library to develop my first game, its awesome. I 
had no idea where to start and its helping me a lot! 
> 
> Date: Tue, 21 Oct 2014 10:47:24 +1100
> From: alec@swapoff.org
> Subject: Re: [entityx] memory leak
> To: entityx@librelist.com
> 
> Hi!
> 
> Yes, it appears there is. I’ve fixed it and added a test case.
> 
> I think this crept in during the move to pools :(
> 
> Thanks for finding it,
> Alec
> On Tuesday, 21 October 2014 at 2:19 am, giovani milanez wrote:
> 
> Compile the program:
> 
> struct Test : entityx::Component<Test>
> {
>     Test() : vec_({0.1, 1.3, 1.6}){};
> 
>     std::vector<float> vec_;
> };
> 
> int main()
> {
>     entityx::EntityX e;
>     auto test = e.entities.create();
>     test.assign<Test>();
> }
> 
> Run with valgrind (memory leak detector tool):
> valgrind --leak-check=full YOUR_PROGRAM
> 
> Results:
> 
> giovani@brytec-giovani:~/workspace-luna/SpaceTD/Debug$ valgrind 
--leak-check=full ./SpaceTD
> ==15850== Memcheck, a memory error detector
> ==15850== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
> ==15850== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
> ==15850== Command: ./SpaceTD
> ==15850== 
> ==15850== 
> ==15850== HEAP SUMMARY:
> ==15850==     in use at exit: 12 bytes in 1 blocks
> ==15850==    total heap usage: 17 allocs, 16 frees, 99,064 bytes allocated
> ==15850== 
> ==15850== 12 bytes in 1 blocks are definitely lost in loss record 1 of 1
> ==15850==    at 0x402BE94: operator new(unsigned int) (in 
/usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
> ==15850==    by 0x804C33F: 
__gnu_cxx::new_allocator<float>::allocate(unsigned int, void const*) 
(new_allocator.h:104)
> ==15850==    by 0x804C1AB: std::_Vector_base<float, 
std::allocator<float> >::_M_allocate(unsigned int) (in 
/home/giovani/workspace-luna/SpaceTD/Debug/SpaceTD)
> ==15850==    by 0x804C0C7: std::_Vector_base<float, 
std::allocator<float> >::_M_create_storage(unsigned int) 
(stl_vector.h:181)
> ==15850==    by 0x804BD5E: std::_Vector_base<float, 
std::allocator<float> >::_Vector_base(unsigned int, std::allocator<float> 
const&) (stl_vector.h:136)
> ==15850==   ; ; ;  by 0x804B85B: std::vector<float, 
std::allocator<float> >::vector(std::vector<float, std::allocator<float> >
const&) (stl_vector.h:312)
> ==15850==    by 0x809F694: Test::Test(std::vector<float, 
std::allocator<float> >&) (SpaceTD.cpp:14)
> ==15850==    by 0x809F79A: 
_ZN7entityx13EntityManager6assignI4TestIRSt6vectorIfSaIfEEEEENS_15ComponentHandleIT_EENS_6Entity2IdEDpOT0_
(Entity.h:520)
> ==15850==    by 0x809F70D: 
_ZN7entityx6Entity6assignI4TestIRSt6vectorIfSaIfEEEEENS_15ComponentHandleIT_EEDpOT0_
(Entity.h:823)
> ==15850==    by 0x809F590: main (SpaceTD.cpp:30)
> ==15850== 
> ==15850== LEAK SUMMARY:
> ==15850==    definitely lost: 12 bytes in 1 blocks
> ==15850==    indirectly lost: 0 bytes in 0 blocks
> ==15850==      possibly lost: 0 bytes in 0 blocks
> ==15850==    still reachable: 0 bytes i n 0 blocks
> ==15850==         suppressed: 0 bytes in 0 blocks
> ==15850== 
> ==15850== For counts of detected and suppressed errors, rerun with: -v
> ==15850== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
> 
> gcc version: g++ (Ubuntu 4.8.1-2ubuntu1~13.04) 4.8.1
> 
> Date: Mon, 20 Oct 2014 11:08:47 -0400
> From: isra017@gmail.com
> Subject: Re: [entityx] memory leak
> To: entityx@librelist.com
> 
> What is the diagnostic that lead you to believe there is a memory leak?
> 
> On Mon, Oct 20, 2014 at 10:11 AM, giovani milanez 
<giovani_milanez@hotmail.com> wrote:
> Hi, i realized that components with std::vector member leaks memory, why?
> Example:
> 
> struct Test : entityx::Component<Test>
> {
>     Test() : vec_({0.1, 1.3, 1.6}){};
> 
>     std::vector<float> vec_;
> };
> 
> int main()
> {
>     entityx::EntityX e;
>     auto test = e.entities.create();
>     test.assign<Test>();
> }
> 
> 

Re: [entityx] memory leak

From:
Israël Hallé
Date:
2014-10-20 @ 15:08
What is the diagnostic that lead you to believe there is a memory leak?

On Mon, Oct 20, 2014 at 10:11 AM, giovani milanez <
giovani_milanez@hotmail.com> wrote:

> Hi, i realized that components with std::vector member leaks memory, why?
> Example:
>
> struct Test : entityx::Component<Test>
> {
>     Test() : vec_({0.1, 1.3, 1.6}){};
>
>     std::vector<float> vec_;
> };
>
> int main()
> {
>     entityx::EntityX e;
>     auto test = e.entities.create();
>     test.assign<Test>();
> }
>

Re: [entityx] memory leak

From:
giovani milanez
Date:
2014-10-20 @ 15:19
Compile the program:

struct Test : entityx::Component<Test>
{
    Test() : vec_({0.1, 1.3, 1.6}){};

    std::vector<float> vec_;
};

int main()
{
    entityx::EntityX e;
    auto test = e.entities.create();
    test.assign<Test>();
}

Run with valgrind (memory leak detector tool):
valgrind --leak-check=full YOUR_PROGRAM

Results:

giovani@brytec-giovani:~/workspace-luna/SpaceTD/Debug$ valgrind 
--leak-check=full ./SpaceTD
==15850== Memcheck, a memory error detector
==15850== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==15850== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==15850== Command: ./SpaceTD
==15850== 
==15850== 
==15850== HEAP SUMMARY:
==15850==     in use at exit: 12 bytes in 1 blocks
==15850==   total heap usage: 17 allocs, 16 frees, 99,064 bytes allocated
==15850== 
==15850== 12 bytes in 1 blocks are definitely lost in loss record 1 of 1
==15850==    at 0x402BE94: operator new(unsigned int) (in 
/usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==15850==    by 0x804C33F: 
__gnu_cxx::new_allocator<float>::allocate(unsigned int, void const*) 
(new_allocator.h:104)
==15850==    by 0x804C1AB: std::_Vector_base<float, std::allocator<float> 
>::_M_allocate(unsigned int) (in 
/home/giovani/workspace-luna/SpaceTD/Debug/SpaceTD)
==15850==    by 0x804C0C7: std::_Vector_base<float, std::allocator<float> 
>::_M_create_storage(unsigned int) (stl_vector.h:181)
==15850==    by 0x804BD5E: std::_Vector_base<float, std::allocator<float> 
>::_Vector_base(unsigned int, std::allocator<float> const&) 
(stl_vector.h:136)
==15850==    by 0x804B85B: std::vector<float, std::allocator<float> 
>::vector(std::vector<float, std::allocator<float> > const&) 
(stl_vector.h:312)
==15850==    by 0x809F694: Test::Test(std::vector<float, 
std::allocator<float> >&) (SpaceTD.cpp:14)
==15850==    by 0x809F79A: 
_ZN7entityx13EntityManager6assignI4TestIRSt6vectorIfSaIfEEEEENS_15ComponentHandleIT_EENS_6Entity2IdEDpOT0_
(Entity.h:520)
==15850==    by 0x809F70D: 
_ZN7entityx6Entity6assignI4TestIRSt6vectorIfSaIfEEEEENS_15ComponentHandleIT_EEDpOT0_
(Entity.h:823)
==15850==    by 0x809F590: main (SpaceTD.cpp:30)
==15850== 
==15850== LEAK SUMMARY:
==15850==    definitely lost: 12 bytes in 1 blocks
==15850==    indirectly lost: 0 bytes in 0 blocks
==15850==      possibly lost: 0 bytes in 0 blocks
==15850==    still reachable: 0 bytes in 0 blocks
==15850==         suppressed: 0 bytes in 0 blocks
==15850== 
==15850== For counts of detected and suppressed errors, rerun with: -v
==15850== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

gcc version: g++ (Ubuntu 4.8.1-2ubuntu1~13.04) 4.8.1

Date: Mon, 20 Oct 2014 11:08:47 -0400
From: isra017@gmail.com
Subject: Re: [entityx] memory leak
To: entityx@librelist.com

What is the diagnostic that lead you to believe there is a memory leak?
On Mon, Oct 20, 2014 at 10:11 AM, giovani milanez 
<giovani_milanez@hotmail.com> wrote:



Hi, i realized that components with std::vector member leaks memory, why?
Example:

struct Test : entityx::Component<Test>
{
    Test() : vec_({0.1, 1.3, 1.6}){};

    std::vector<float> vec_;
};

int main()
{
    entityx::EntityX e;
    auto test = e.entities.create();
    test.assign<Test>();
}
 		 	   		  

 		 	   		  

Re: [entityx] memory leak

From:
Alec Thomas
Date:
2014-10-20 @ 23:47
Hi!  

Yes, it appears there is. I’ve fixed it and added a test case.

I think this crept in during the move to pools :(

Thanks for finding it,
Alec


On Tuesday, 21 October 2014 at 2:19 am, giovani milanez wrote:

> Compile the program:
>  
> struct Test : entityx::Component<Test>
> {
>     Test() : vec_({0.1, 1.3, 1.6}){};
>  
>     std::vector<float> vec_;
> };
>  
> int main()
> {
>     entityx::EntityX e;
>     auto test = e.entities.create();
>     test.assign<Test>();
> }
>  
> Run with valgrind (memory leak detector tool):
> valgrind --leak-check=full YOUR_PROGRAM
>  
> Results:
>  
> giovani@brytec-giovani:~/workspace-luna/SpaceTD/Debug$ valgrind 
--leak-check=full ./SpaceTD
> ==15850== Memcheck, a memory error detector
> ==15850== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
> ==15850== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
> ==15850== Command: ./SpaceTD
> ==15850==  
> ==15850==  
> ==15850== HEAP SUMMARY:
> ==15850==     in use at exit: 12 bytes in 1 blocks
> ==15850==    total heap usage: 17 allocs, 16 frees, 99,064 bytes allocated
> ==15850==  
> ==15850== 12 bytes in 1 blocks are definitely lost in loss record 1 of 1
> ==15850==    at 0x402BE94: operator new(unsigned int) (in 
/usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
> ==15850==    by 0x804C33F: 
__gnu_cxx::new_allocator<float>::allocate(unsigned int, void const*) 
(new_allocator.h:104)
> ==15850==    by 0x804C1AB: std::_Vector_base<float, 
std::allocator<float> >::_M_allocate(unsigned int) (in 
/home/giovani/workspace-luna/SpaceTD/Debug/SpaceTD)
> ==15850==    by 0x804C0C7: std::_Vector_base<float, 
std::allocator<float> >::_M_create_storage(unsigned int) 
(stl_vector.h:181)
> ==15850==    by 0x804BD5E: std::_Vector_base<float, 
std::allocator<float> >::_Vector_base(unsigned int, std::allocator<float> 
const&) (stl_vector.h:136)
> ==15850==   ;  by 0x804B85B: std::vector<float, std::allocator<float> 
>::vector(std::vector<float, std::allocator<float> > const&) 
(stl_vector.h:312)
> ==15850==    by 0x809F694: Test::Test(std::vector<float, 
std::allocator<float> >&) (SpaceTD.cpp:14)
> ==15850==    by 0x809F79A: 
_ZN7entityx13EntityManager6assignI4TestIRSt6vectorIfSaIfEEEEENS_15ComponentHandleIT_EENS_6Entity2IdEDpOT0_
(Entity.h:520)
> ==15850==    by 0x809F70D: 
_ZN7entityx6Entity6assignI4TestIRSt6vectorIfSaIfEEEEENS_15ComponentHandleIT_EEDpOT0_
(Entity.h:823)
> ==15850==    by 0x809F590: main (SpaceTD.cpp:30)
> ==15850==  
> ==15850== LEAK SUMMARY:
> ==15850==    definitely lost: 12 bytes in 1 blocks
> ==15850==    indirectly lost: 0 bytes in 0 blocks
> ==15850==      possibly lost: 0 bytes in 0 blocks
> ==15850==    still reachable: 0 bytes i n 0 blocks
> ==15850==         suppressed: 0 bytes in 0 blocks
> ==15850==  
> ==15850== For counts of detected and suppressed errors, rerun with: -v
> ==15850== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
>  
> gcc version: g++ (Ubuntu 4.8.1-2ubuntu1~13.04) 4.8.1
>  
> Date: Mon, 20 Oct 2014 11:08:47 -0400
> From: isra017@gmail.com (mailto:isra017@gmail.com)
> Subject: Re: [entityx] memory leak
> To: entityx@librelist.com (mailto:entityx@librelist.com)
>  
> What is the diagnostic that lead you to believe there is a memory leak?
>  
> On Mon, Oct 20, 2014 at 10:11 AM, giovani milanez 
<giovani_milanez@hotmail.com (mailto:giovani_milanez@hotmail.com)> wrote:
> > Hi, i realized that components with std::vector member leaks memory, why?
> > Example:
> >  
> > struct Test : entityx::Component<Test>
> > {
> >     Test() : vec_({0.1, 1.3, 1.6}){};
> >  
> >     std::vector<float> vec_;
> > };
> >  
> > int main()
> > {
> >     entityx::EntityX e;
> >     auto test = e.entities.create();
> >     test.assign<Test>();
> > }
>