U++ framework
Do not panic. Ask here before giving up.

Home » U++ Library support » U++ Core » This is heap leak? (a Ptr use new,no delete,heap leak)
Re: This is heap leak? [message #61788 is a reply to message #61787] Tue, 02 September 2025 11:41 Go to previous message
koldo is currently offline  koldo
Messages: 3458
Registered: August 2008
Senior Veteran
Hi Fzx374cn

In addition Ptr goes with Pte.
This is a version of your example. It is not very meaningful but you can see that your pointer does not produce a heap problem, it just returns 0 if the pointed data (Foo data) is out of scope:

struct Foo : Pte<Foo> {
    Button but;
};

class Test : public TopWindow {
public:
	void Start() {
		Foo data;
		ptr = &data;
		str << "During: " << (void*)~ptr << "\n";
	}
	Ptr<Foo> ptr;
	String str;
};

GUI_APP_MAIN
{
	Test t;
	t.str << "Before: " << (void*)~t.ptr << "\n";
	t.Start();
	t.Run();
	t.str << "After:  " << (void*)~t.ptr;
	Exclamation(DeQtfLf(t.str));
}


This shows:
Before: 0x0
During: 0x6fad31f508
After:  0x0


Best regards
IƱaki
 
Read Message icon3.gif
Read Message
Read Message
Previous Topic: VectorMap iteration
Next Topic: Unable to Compile ScatterCtrl Example on Debian 12 (ARM64, Clang 18) -- Eigen Package Error
Goto Forum:
  


Current Time: Fri May 15 08:05:53 GMT+2 2026

Total time taken to generate the page: 0.00483 seconds