Page 1 of 1

[Solved] ScreenOutput big memory leak

Posted: Thu Oct 11, 2012 6:38 pm
by kenmo
Hopefully my last bug report :)

I was looking for causes of slowdown, and I noticed my game's memory usage was reaching 800+ MB! I narrowed it down to the Start/StopDrawing block and specifically the ScreenOutput command...

Previously, I added a ScreenOutput() check before calling StartDrawing() to prevent occasional null pointer errors I was having at that code line. But removing that check seems to fix the memory leak.

On OSX 10.7:
without checking ScreenOutput(), ~60 MB usage
checking ScreenOutput(), 800+ MB

Code: Select all

InitSprite()
OpenWindow(0, 0, 0, 480, 360, "ScreenOutput memory", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, 480, 360, 0, 0, 0)

Repeat
  ClearScreen(0) ; this doesn't make a difference
  
  ; Use this line: memory usage shoots up to 800 MB!
  If (ScreenOutput() And StartDrawing(ScreenOutput()))
  
  ; Use this line: memory usage sits around 60 MB
  ;If (StartDrawing(ScreenOutput()))
  
    StopDrawing()
  EndIf
  
  FlipBuffers() ; this doesn't make a difference
Until WaitWindowEvent(10) = #PB_Event_CloseWindow

Re: [PB 5.0 b4] ScreenOutput big memory leak [OSX 10.7]

Posted: Thu Oct 11, 2012 6:47 pm
by Fred
Your code is faulty, ScreenOutput() is only valid within StartDrawing(), you can not 'check' it. The memory allocated in ScreenOutput() is released on StopDrawing(), so if you call it twice it will leak.

Re: [PB 5.0 b4] ScreenOutput big memory leak [OSX 10.7]

Posted: Thu Oct 11, 2012 6:53 pm
by kenmo
OK, that is good to know. I don't usually check it like that, so I will change it back and maybe the null pointer error is unrelated.

Perhaps a warning about proper use could be added to the ScreenOutput() help page.

Re: [Solved] ScreenOutput big memory leak

Posted: Thu Oct 11, 2012 9:52 pm
by Andre
Done. ScreenOutput() help improved :D

Re: [Solved] ScreenOutput big memory leak

Posted: Thu Oct 11, 2012 9:58 pm
by Fred
It's the same for all xxxOutput()

Re: [Solved] ScreenOutput big memory leak

Posted: Thu Oct 11, 2012 11:11 pm
by Andre
Fred wrote:It's the same for all xxxOutput()
Added improved descriptions + small example to each xxxOutput() command in the manual! :D