[Solved] ScreenOutput big memory leak

Just starting out? Need help? Post your questions and find answers here.
User avatar
kenmo
Addict
Addict
Posts: 2081
Joined: Tue Dec 23, 2003 3:54 am

[Solved] ScreenOutput big memory leak

Post 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
Last edited by kenmo on Thu Oct 11, 2012 6:53 pm, edited 1 time in total.
Fred
Administrator
Administrator
Posts: 18499
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

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

Post 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.
User avatar
kenmo
Addict
Addict
Posts: 2081
Joined: Tue Dec 23, 2003 3:54 am

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

Post 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.
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2158
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: [Solved] ScreenOutput big memory leak

Post by Andre »

Done. ScreenOutput() help improved :D
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
Fred
Administrator
Administrator
Posts: 18499
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: [Solved] ScreenOutput big memory leak

Post by Fred »

It's the same for all xxxOutput()
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2158
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: [Solved] ScreenOutput big memory leak

Post by Andre »

Fred wrote:It's the same for all xxxOutput()
Added improved descriptions + small example to each xxxOutput() command in the manual! :D
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
Post Reply