Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » Why this one leaks ?
Why this one leaks ? [message #33766] Sun, 11 September 2011 17:07 Go to next message
mdelfede is currently offline  mdelfede
Messages: 1307
Registered: September 2007
Ultimate Contributor

#include <Core/Core.h>

using namespace Upp;

class Base : public Pte<Base>
{
	public:
		String BaseData;
		Base() { BaseData = "Sample data in Base class"; }
};
	
CONSOLE_APP_MAIN
{
	Ptr<Base> b = new Base;
	
}



Shouldn't be created element freed on Ptr destruction ?
Here the Upp log :

Heap leaks detected:

--memory-breakpoint__ 1120 : Memory at 0x7f70bdb87210, size 0x20 = 32
    +0 0x00007F70BDB87210 53 61 6D 70 6C 65 20 64 61 74 61 20 69 6E 20 42     Sample data in B
   +16 0x00007F70BDB87220 61 73 65 20 63 6C 61 73 73 00 65 65 46 72 65 65     ase class.eeFree

--memory-breakpoint__ 1119 : Memory at 0x7f70bdb872b0, size 0x28 = 40
    +0 0x00007F70BDB872B0 00 00 00 00 00 00 00 00 19 00 00 00 46 72 65 65     ............Free
   +16 0x00007F70BDB872C0 10 72 B8 BD 70 7F 00 00 10 72 B8 BD 70 7F 00 00     .r¸½p...r¸½p..
   +32 0x00007F70BDB872D0 19 00 00 00 00 00 1F 0F                             ........        
Re: Why this one leaks ? [message #33767 is a reply to message #33766] Sun, 11 September 2011 17:22 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
mdelfede wrote on Sun, 11 September 2011 11:07


#include <Core/Core.h>

using namespace Upp;

class Base : public Pte<Base>
{
	public:
		String BaseData;
		Base() { BaseData = "Sample data in Base class"; }
};
	
CONSOLE_APP_MAIN
{
	Ptr<Base> b = new Base;
	
}



Shouldn't be created element freed on Ptr destruction ?
Here the Upp log :




You got it wrong way. b is set NULL on Base destructoin, not other way around.

U++ deliberately stays away from "smart pointers" used to manage shared resources.

Mirek

[Updated on: Sun, 11 September 2011 17:22]

Report message to a moderator

Re: Why this one leaks ? [message #33768 is a reply to message #33767] Sun, 11 September 2011 17:27 Go to previous messageGo to next message
mdelfede is currently offline  mdelfede
Messages: 1307
Registered: September 2007
Ultimate Contributor
Argh.... so I don't see the real usefulness of Ptr stuff, If I must remember to delete the pointed data....
Well, so no smart pointers in Upp,ok Smile

Max
Re: Why this one leaks ? [message #33770 is a reply to message #33768] Sun, 11 September 2011 20:17 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
mdelfede wrote on Sun, 11 September 2011 11:27

Argh.... so I don't see the real usefulness of Ptr stuff, If I must remember to delete the pointed data....
Well, so no smart pointers in Upp,ok Smile

Max



Well, Ptr is not intented to delete data, but to know that data was destructed...

Without it, GUI would be much harder to implement.

Mirek
Re: Why this one leaks ? [message #33777 is a reply to message #33770] Mon, 12 September 2011 13:54 Go to previous messageGo to next message
Mindtraveller is currently offline  Mindtraveller
Messages: 917
Registered: August 2007
Location: Russia, Moscow rgn.
Experienced Contributor

You may use One<MyClass> container to have it auto-deleted.
Re: Why this one leaks ? [message #33779 is a reply to message #33777] Mon, 12 September 2011 19:50 Go to previous message
mdelfede is currently offline  mdelfede
Messages: 1307
Registered: September 2007
Ultimate Contributor
Yep, I've understood that and I already used One.
The only caveat of One is that you must care when you pick it, but thinking a bit about it it's not a bad thing... makes me to code better and with more care Smile

Max
Previous Topic: read/write to pipe /dev/rtp..?
Next Topic: Array : swapping element with a pointer
Goto Forum:
  


Current Time: Fri Apr 19 01:01:22 CEST 2024

Total time taken to generate the page: 0.05175 seconds