6.01 Weird container / canvas memory leak

Post bugreports for the Windows version here
Justin
Addict
Addict
Posts: 829
Joined: Sat Apr 26, 2003 2:49 pm

6.01 Weird container / canvas memory leak

Post by Justin »

If you run this code, grab a window corner and start resizing the window constantly the ram usage of the program keeps increasing until you stop resizing the window. W10 X64

Code: Select all

EnableExplicit

Procedure on_size()
	ResizeGadget(1, 0, 0, WindowWidth(0) / 2, WindowHeight(0) / 2)
	ResizeGadget(2, WindowWidth(0) / 2, 0, WindowWidth(0) / 2, WindowHeight(0) / 2)
	ResizeGadget(3, 0, WindowHeight(0) / 2, WindowWidth(0) / 2, WindowHeight(0) / 2)
	ResizeGadget(4, WindowWidth(0) / 2, WindowHeight(0) / 2, WindowWidth(0) / 2, WindowHeight(0) / 2)

; 	ResizeGadget(5, 0, 0, WindowWidth(0), WindowHeight(0))
EndProcedure

OpenWindow(0, 10, 10, 600, 400, "Test", #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget | #PB_Window_SystemMenu)
BindEvent(#PB_Event_SizeWindow, @on_size())
ContainerGadget(1, 0, 0, 0, 0)
CloseGadgetList()
ContainerGadget(2, 0, 0, 0, 0)
CloseGadgetList()
ContainerGadget(3, 0, 0, 0, 0)
CloseGadgetList()
ContainerGadget(4, 0, 0, 0, 0)
CloseGadgetList()

SetGadgetColor(1, #PB_Gadget_BackColor, RGB(255, 0, 0))
SetGadgetColor(2, #PB_Gadget_BackColor, RGB(0, 255, 0))
SetGadgetColor(3, #PB_Gadget_BackColor, RGB(0, 0, 255))
SetGadgetColor(4, #PB_Gadget_BackColor, RGB(255, 0, 255))

; ButtonGadget(5, 0, 0, 0, 0, "Test")
on_size()

Repeat

Until WaitWindowEvent() = #PB_Event_CloseWindow
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: 6.01 Weird container / canvas memory leak

Post by infratec »

With PB 6.01 b5 Windows x86 on Win10 x64 (Assembler backend)
I have 1.9MB after start.
During continous resizing it grows up to 2.7MB.
But after I stop resizing it went back to 1.,9MB.

What are your values? C or Asm?
And does the memory usage stays high after resizing?

I will update to 6,01 final now.
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: 6.01 Weird container / canvas memory leak

Post by infratec »

Now with 6.01 final:

In all combinations, the x86 version went always back with the memory usage.
It is not constantly growing.
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: 6.01 Weird container / canvas memory leak

Post by skywalk »

Hard to confirm. I disable animations on Windows 10 PRO.

After compiling x64 with CBE+optimizer.
1308k ram on start.
1312k ram after resize.
1312k ram after repeated resizing.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Denis
Enthusiast
Enthusiast
Posts: 704
Joined: Fri Apr 25, 2003 5:10 pm
Location: Doubs - France

Re: 6.01 Weird container / canvas memory leak

Post by Denis »

Not confirmed on my computer.
Window 11 X64 Pro (version 22H2)
32 GB RAM
PB 6.01 LTS X64

All compilation with debugger Off.

compiling x64 with ASM witout optimizer.
1312k ram on start.
1312k ram after first resizing.
1288k ram after repeated resizing.

compiling x64 with ASM with optimizer.
1300k ram on start.
1308k ram after first resizing.
1308k ram after repeated resizing.

compiling x64 with CBE witout optimizer.
1276k ram on start.
1276k ram after resize.
1312k ram after repeated resizing.

compiling x64 with CBE with optimizer.
1276k ram on start.
1276k ram after resize.
1312k ram after repeated resizing.
A+
Denis
Justin
Addict
Addict
Posts: 829
Joined: Sat Apr 26, 2003 2:49 pm

Re: 6.01 Weird container / canvas memory leak

Post by Justin »

Tested on three different computers W10 Pro X64, same results on all of them, 6.01 Final, default compiler C Backend no longer appears in final. Debugger enabled / disabled makes no difference.
In all cases when you stop resizing the ram goes to normal.

How long do you keep resizing the window? You have to do it constantly without releasing the mouse. After one minute i reach 8MB easily and grows until i release the mouse.
Image
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: 6.01 Weird container / canvas memory leak

Post by mk-soft »

It is a Windows internal story with the memory management.

With windows I sometimes minimize the window before I hide it (HideWindow) so I force windows to clean up the memory.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Justin
Addict
Addict
Posts: 829
Joined: Sat Apr 26, 2003 2:49 pm

Re: 6.01 Weird container / canvas memory leak

Post by Justin »

I am aware of that windows memory story. But this looks more like a PB issue, if you run the following code that uses a pure api container and does not use BindEvent() the memory stays at 1.4MB rock solid, it never goes past that no matter how heavily you resize the window for any amount of time.

I would say is some event data or drawing object not being released, maybe is inherent to windows memory management or to PB. Not a big problem because the memory is released when the resizing ends, but it is something Fred could look at.

Code: Select all

EnableExplicit

#CONT_CLASS = "mycont"

Global.i hwCont

Declare on_size()

Procedure contProc(hwnd.i, msg.l, wparam.i, lparam.i)
	Select msg
		Case #WM_PAINT
			Protected.PAINTSTRUCT ps
			Protected.i hdc, hbr
			
			hdc = BeginPaint_(hwnd, @ps)
			hbr = CreateSolidBrush_(RGB(255, 0, 0))
			FillRect_(hdc, @ps\rcPaint, hbr)
			DeleteObject_(hbr)
			EndPaint_(hwnd, @ps)
			ProcedureReturn 0
		
	EndSelect
	
	ProcedureReturn DefWindowProc_(hwnd, msg, wparam, lparam)
EndProcedure

Procedure wnd_proc(hwnd.i, msg.l, wparam.i, lparam.i)
	Select msg
		Case #WM_SIZE
; 			on_size()
			MoveWindow_(hwCont, 0, 0, DesktopScaledX(WindowWidth(0)), DesktopScaledY(WindowHeight(0)), #True)
			ProcedureReturn 0
			
	EndSelect
	
	ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure

Procedure registerClass()
	Protected.WNDCLASS wc
	Protected.s className
	
	className = #CONT_CLASS
	wc\hInstance = GetModuleHandle_(0)
	wc\lpfnWndProc = @contProc()
	wc\style = #CS_HREDRAW | #CS_VREDRAW
	wc\lpszClassName = @className
	
	RegisterClass_(@wc)
EndProcedure

Procedure on_size()
; 	ResizeGadget(1, 0, 0, WindowWidth(0) / 2, WindowHeight(0) / 2)
; 	ResizeGadget(2, WindowWidth(0) / 2, 0, WindowWidth(0) / 2, WindowHeight(0) / 2)
; 	ResizeGadget(3, 0, WindowHeight(0) / 2, WindowWidth(0) / 2, WindowHeight(0) / 2)
; 	ResizeGadget(4, WindowWidth(0) / 2, WindowHeight(0) / 2, WindowWidth(0) / 2, WindowHeight(0) / 2)

; 	ResizeGadget(5, 0, 0, WindowWidth(0), WindowHeight(0))

	MoveWindow_(hwCont, 0, 0, DesktopScaledX(WindowWidth(0)), DesktopScaledY(WindowHeight(0)), #True)
EndProcedure

registerClass()
OpenWindow(0, 10, 10, 600, 400, "Test", #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget | #PB_Window_SystemMenu)
; BindEvent(#PB_Event_SizeWindow, @on_size())

hwCont = CreateWindowEx_(0, #CONT_CLASS, "", #WS_CHILD | #WS_VISIBLE, 0, 0, 0, 0, WindowID(0), 0, GetModuleHandle_(0), 0)

; ContainerGadget(1, 0, 0, 0, 0)
; CloseGadgetList()
; ContainerGadget(2, 0, 0, 0, 0)
; CloseGadgetList()
; ContainerGadget(3, 0, 0, 0, 0)
; CloseGadgetList()
; ContainerGadget(4, 0, 0, 0, 0)
; CloseGadgetList()
; 
; SetGadgetColor(1, #PB_Gadget_BackColor, RGB(255, 0, 0))
; SetGadgetColor(2, #PB_Gadget_BackColor, RGB(0, 255, 0))
; SetGadgetColor(3, #PB_Gadget_BackColor, RGB(0, 0, 255))
; SetGadgetColor(4, #PB_Gadget_BackColor, RGB(255, 0, 255))

SetWindowCallback(@wnd_proc())

; ButtonGadget(5, 0, 0, 0, 0, "Test")
on_size()

Repeat

Until WaitWindowEvent() = #PB_Event_CloseWindow

Post Reply