Page 1 of 1

Free WebGadget Memory ?

Posted: Sat Aug 30, 2008 9:25 am
by Rascal
Free WebGadget Memory ???

Code: Select all


Enumeration
  #Window_0
  #Window_1
  #Button_0
  #Button_1
  #StatusBar_0
EndEnumeration

Global NewList WebBrowser.l()

Procedure Open_Window_1()
Url.s = "http://www.purebasic.fr/"
EnableWindow_(WindowID(#Window_0),#False) 
If OpenWindow(#Window_1,000,000,530,215,"WebBrowser",#PB_Window_SystemMenu|#PB_Window_TitleBar|#PB_Window_ScreenCentered)
 If CreateStatusBar(#StatusBar_0,WindowID(#Window_1))
 EndIf
 If CreateGadgetList(WindowID(#Window_1))
    ButtonGadget(#Button_1,110,010,090,030,"Release",#PB_Button_Default)
    For i = 1 To 1000
     AddElement(WebBrowser())
     WebBrowser() = i + 10
     WebGadget(i+10,005,005,100,100,Url)
     StatusBarText(#StatusBar_0,0,Str(i),#PB_StatusBar_Center)
    Next i 
 EndIf
EndIf
EndProcedure

If OpenWindow(#Window_0,278,168,109,055,#NULL$,#PB_Window_SystemMenu|#PB_Window_TitleBar|#PB_Window_ScreenCentered)
 If CreateGadgetList(WindowID(#Window_0))
    ButtonGadget(#Button_0,010,010,090,030,"Open",#PB_Button_Default)
 EndIf
 Repeat 
   EventID  = WaitWindowEvent()
   WindowID = EventWindow()
   Select WindowID
      Case #Window_0
        Select EventID
          Case #PB_Event_Gadget
            Select EventGadget()
              Case #Button_0
                Open_Window_1()
            EndSelect
        EndSelect
      Case #Window_1
        Select EventID
          Case #PB_Event_Gadget
            Select EventGadget()
              Case #Button_1
                ForEach WebBrowser()
                  SetGadgetText(WebBrowser(),"about:blank")
                Next
            EndSelect
          Case #PB_Event_CloseWindow
            EnableWindow_(WindowID(#Window_0),#True)
            CloseWindow(#Window_1)
        EndSelect
   EndSelect   
 Until WindowID = #Window_0 And EventID = #PB_Event_CloseWindow
EndIf

Posted: Sat Aug 30, 2008 1:21 pm
by Sparkie
1000 WebGadgets seems a bit extreme to me Rascal. I ask you again...what are you trying to accomplish here? Surely there is a better path for you to follow. ;)

A question like
Free WebGadget Memory ???
doesn't give us much to work with. My answer to you is Yes.

Posted: Sat Aug 30, 2008 1:22 pm
by srod
My answer is 'yes please, I'll have some webgadget memory!' - I'll take anything if it is free! :)

Posted: Sat Aug 30, 2008 10:00 pm
by Fred
Such topic without any english-like question will be locked.

Re:

Posted: Mon Oct 10, 2011 3:39 pm
by MachineCode
I think I have the same question as Rascal. I want to free the memory used by the WebGadget. For example, if I run the following code, the Windows Task Manager shows 14000 KB used by my PureBasic exe at startup, but after loading the website, it jumps to 96000 KB. Then, if I clear the WebGadget contents by setting it to "about:blank", the memory jumps down to 71000 KB, but still isn't totally freed back to 14000 KB as per exe startup. So is there a way to free it? Especially when we load LARGE websites into the gadget?

Other things I've tried: using FreeGadget(0) and recreating the WebGadget; didn't free the memory (it remained at 71000 KB!). And minimizing the window (per http://www.purebasic.fr/english/viewtop ... 13&t=29582) is no help as some of my apps don't show a visible window at all, or don't have a minimize gadget for operational reasons.

Code: Select all

If OpenWindow(0,200,200,800,600,"WebGadget",#PB_Window_SystemMenu)
  WebGadget(0,10,10,785,500,"http://news.cnet.com/")
  ButtonGadget(1,10,520,250,30,"Clear WebGadget and its memory")
  Repeat
    event=WaitWindowEvent()
    If event=#PB_Event_Gadget And EventGadget()=1
      SetGadgetText(0,"about:blank")
    EndIf
  Until event=#PB_Event_CloseWindow
EndIf

Re: Free WebGadget Memory ?

Posted: Mon Oct 10, 2011 4:13 pm
by luis
@MachineCode

You can try this

Code: Select all

Prototype.i proto_EmptyWorkingSet (hProcess)

Procedure.i EmptyWorkingSet (hProcess)
 ; Windows XP and later, Windows 2000 Professional, or Windows NT Workstation 4.0
 
 Protected EmptyWorkingSet_.proto_EmptyWorkingSet 
 Protected hDll, iRetVal = 0
 
 hDll = OpenLibrary(#PB_Any, "Psapi.dll")
 
 If hDll 
    EmptyWorkingSet_ = GetFunction(hDll, "EmptyWorkingSet")
    
    If EmptyWorkingSet_       
        If EmptyWorkingSet_(hProcess) <> 0
            iRetVal = 1
        EndIf
    EndIf
        
    CloseLibrary(hDll)
 EndIf
 
 ProcedureReturn iRetVal 
EndProcedure



If OpenWindow(0,200,200,800,600,"WebGadget",#PB_Window_SystemMenu)
  WebGadget(0,10,10,785,500,"http://news.cnet.com/")
  ButtonGadget(1,10,520,250,30,"Clear WebGadget and its memory")
  Repeat
    event=WaitWindowEvent()
    If event=#PB_Event_Gadget And EventGadget()=1
      SetGadgetText(0,"about:blank")
      EmptyWorkingSet (GetCurrentProcess_())
    EndIf
  Until event=#PB_Event_CloseWindow
EndIf
But it has only a cosmetic value, to give you a false peace of mind. There is no need to force the OS to do so, the high value you see it's normal and the OS will take care of it IF and WHEN needed.

Re: Re:

Posted: Mon Oct 10, 2011 10:43 pm
by Kiffi
@MachineCode: Not tested, but what about

Code: Select all

SetGadgetItemText(0, #PB_Web_HtmlCode, "")
?

Greetings ... Kiffi

Re: Free WebGadget Memory ?

Posted: Tue Oct 11, 2011 12:07 am
by MachineCode
@Kiffi, SetGadgetItemText(0, #PB_Web_HtmlCode, "") reduces memory to about 70,000 KB, which is not quite the best. Thanks anyway.

@luis: Your EmptyWorkingSet() procedure reduces memory to about 30,000 KB, which is far better. Thank you!

Shame that we can't lose ALL memory that the WebGadget used, though. But if Windows takes care of it later, then I guess it won't be all bad. I was only concerned because my WebGadget loads LOTS of different URLs during use, and I've seen my app in the Task Manager grow to using about 300,000 KB at times, even when I'm finished with the WebGadget, so it would've been nice to free all that memory afterwards.

Re: Free WebGadget Memory ?

Posted: Sun Nov 10, 2019 11:09 pm
by Fredi
After years now in 2019 and PB v5.71 is there a better way to do free WebGadget memory !?
I have a Website monitor app that monitor some live websites with big source, after start monitor program, used memory of it very fast grow up from 70MB to UP 1000MB and then slow and crash !
Why we dont have something like FreeWebGadget() command? because with closing window of WebGadget that memory doesn't free.
Any help?

Re: Free WebGadget Memory ?

Posted: Tue Nov 12, 2019 12:15 pm
by Fredi
No one can help?