Free WebGadget Memory ?

Just starting out? Need help? Post your questions and find answers here.
Rascal
User
User
Posts: 30
Joined: Mon Sep 17, 2007 11:06 pm

Free WebGadget Memory ?

Post 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
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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.
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

My answer is 'yes please, I'll have some webgadget memory!' - I'll take anything if it is free! :)
I may look like a mule, but I'm not a complete ass.
Fred
Administrator
Administrator
Posts: 16686
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Such topic without any english-like question will be locked.
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re:

Post 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
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
User avatar
luis
Addict
Addict
Posts: 3876
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Free WebGadget Memory ?

Post 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.
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
Kiffi
Addict
Addict
Posts: 1357
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: Re:

Post by Kiffi »

@MachineCode: Not tested, but what about

Code: Select all

SetGadgetItemText(0, #PB_Web_HtmlCode, "")
?

Greetings ... Kiffi
Hygge
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: Free WebGadget Memory ?

Post 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.
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
Fredi
Enthusiast
Enthusiast
Posts: 143
Joined: Wed Jul 23, 2008 10:45 pm

Re: Free WebGadget Memory ?

Post 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?
Fredi
Enthusiast
Enthusiast
Posts: 143
Joined: Wed Jul 23, 2008 10:45 pm

Re: Free WebGadget Memory ?

Post by Fredi »

No one can help?
Post Reply