It is currently Wed Sep 18, 2019 7:15 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Function Space does not free memory
PostPosted: Mon Oct 15, 2018 9:55 pm 
Offline
Addict
Addict

Joined: Wed Nov 12, 2008 5:01 pm
Posts: 1050
Location: Russia
Function Space does not free memory. In the task manager, the process uses almost 800 MB of RAM.
Code:
Space(200000000)
Space(400000000)
Space(2)
CallDebugger

_________________
Library XP_Menu_Lib - office menu; HID_Lib - USB Library
Torrent client - pbTorrent (source code); Create driver in PureBasic.


Top
 Profile  
Reply with quote  
 Post subject: Re: Function Space does not free memory
PostPosted: Mon Oct 15, 2018 11:05 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Jun 25, 2014 5:25 pm
Posts: 359
Location: Germany
Yes, it seems that the freeing of string variables has still not been implemented correctly.
Look here: Free Strings / Memory

_________________
Image
Why OpenSource should have a license
PureBasic-CodeArchiv-Rebirth: Git-Repository / Download -- Any help is welcome!
Manjaro Xfce x64 (Main system) :: WindowsXP/Xubuntu x86 (VirtualBox) :: PureBasic (Linux: x86/x64, Windows: x86) :: All are up to date


Top
 Profile  
Reply with quote  
 Post subject: Re: Function Space does not free memory
PostPosted: Tue Oct 16, 2018 12:12 am 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 13, 2010 3:45 pm
Posts: 885
The other question is, where are these strings stored and why should they ever overwrite each other? This code should never be executed by Pb.

_________________
sorry for my bad english


Top
 Profile  
Reply with quote  
 Post subject: Re: Function Space does not free memory
PostPosted: Tue Oct 16, 2018 11:30 am 
Offline
Addict
Addict

Joined: Wed Nov 12, 2008 5:01 pm
Posts: 1050
Location: Russia
Writing to a string variable does not solve the problem.
Code:
s.s=Space(200000000)
s=""
s=Space(40000000)
s=""
s=Space(2)
s=""
CallDebugger

_________________
Library XP_Menu_Lib - office menu; HID_Lib - USB Library
Torrent client - pbTorrent (source code); Create driver in PureBasic.


Top
 Profile  
Reply with quote  
 Post subject: Re: Function Space does not free memory
PostPosted: Sun Dec 02, 2018 10:18 am 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 13612
Location: France
Fixed.


Top
 Profile  
Reply with quote  
 Post subject: Re: [Done] Function Space does not free memory
PostPosted: Sat Jan 12, 2019 8:09 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Jun 25, 2014 5:25 pm
Posts: 359
Location: Germany
Why is the Space() function allowed to free memory, but not:
Code:
s.s = #Null$
; or
s.s = ""
?

Code:
Procedure$ FreeString()
  ProcedureReturn ""
EndProcedure

a$ = Space(1e9) ; Create a string with 1.000.000.000 whitespace characters
CompilerSelect 5
     CompilerCase 0 : a$ = #Null$       ; Thereafter, 1,9 GiB RAM are still in use
     CompilerCase 1 : a$ = ""           ; Thereafter, 1,9 GiB RAM are still in use
     CompilerCase 2 : a$ = Space(0)     ; Thereafter, 1,3 MiB RAM are still in use
     CompilerCase 3 : a$ = Hex(0)       ; Thereafter, 1,3 MiB RAM are still in use
     CompilerCase 4 : a$ = Str(0)       ; Thereafter, 1,3 MiB RAM are still in use
     CompilerCase 5 : a$ = FreeString() ; Thereafter, 1,3 MiB RAM are still in use
CompilerEndSelect
Repeat
   Delay(1)
ForEver

_________________
Image
Why OpenSource should have a license
PureBasic-CodeArchiv-Rebirth: Git-Repository / Download -- Any help is welcome!
Manjaro Xfce x64 (Main system) :: WindowsXP/Xubuntu x86 (VirtualBox) :: PureBasic (Linux: x86/x64, Windows: x86) :: All are up to date


Top
 Profile  
Reply with quote  
 Post subject: Re: [Done] Function Space does not free memory
PostPosted: Tue Jan 15, 2019 12:57 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 13612
Location: France
literal string affectation doesn't create a new buffer, that's why.


Top
 Profile  
Reply with quote  
 Post subject: Re: [Done] Function Space does not free memory
PostPosted: Tue Jan 15, 2019 1:50 pm 
Offline
Addict
Addict

Joined: Wed Nov 12, 2008 5:01 pm
Posts: 1050
Location: Russia
Fred, this line should free the existing buffer.
Code:
s.s = ""
But instead zeroed initial bytes.
Code:
s.s = Space(200000000)
Debug @s
s = ""
Debug @s
Debug ShowMemoryViewer(@s, 10)
Code:
s.s = "12345678"
Debug @s
s = ""
Debug @s
Debug ShowMemoryViewer(@s, 10)
This is a bug!

_________________
Library XP_Menu_Lib - office menu; HID_Lib - USB Library
Torrent client - pbTorrent (source code); Create driver in PureBasic.


Top
 Profile  
Reply with quote  
 Post subject: Re: [Done] Function Space does not free memory
PostPosted: Tue Jan 15, 2019 2:13 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 13612
Location: France
No, it's the intended behaviour. The buffer is freed only on the next real allocation (in real world code it won't be an issue).


Top
 Profile  
Reply with quote  
 Post subject: Re: [Done] Function Space does not free memory
PostPosted: Tue Jan 15, 2019 2:34 pm 
Offline
Addict
Addict

Joined: Wed Nov 12, 2008 5:01 pm
Posts: 1050
Location: Russia
Fred wrote:
it's the intended behaviour.
Where in help it is written about it?

The help is written.
Quote:
#Null$ special string constant to affect a real null value to a string (to free it completely). It can be used as well for API function which sometimes accept NULL instead of a string address.
But it does not work.
Code:
s.s = "12345678"
s = #Null$
ShowMemoryViewer(@s, 10)
Code:
s.s = "12345678"
s = ""
s = #Null$
s = #Empty$
ShowMemoryViewer(@s, 10)
Then why do we need a constant #Null$?

Why did you decide not to free the string buffer? What is the advantage of this?

_________________
Library XP_Menu_Lib - office menu; HID_Lib - USB Library
Torrent client - pbTorrent (source code); Create driver in PureBasic.


Top
 Profile  
Reply with quote  
 Post subject: Re: [Done] Function Space does not free memory
PostPosted: Tue Jan 15, 2019 2:47 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 13612
Location: France
#Null$ correctly free the previous string buffer, it just don't reduce the shared (working space buffer) string buffer.


Top
 Profile  
Reply with quote  
 Post subject: Re: [Done] Function Space does not free memory
PostPosted: Tue Jan 15, 2019 6:19 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Jun 25, 2014 5:25 pm
Posts: 359
Location: Germany
Fred wrote:
literal string affectation doesn't create a new buffer, that's why.
Thanks, now it makes sense.

Fred wrote:
#Null$ correctly free the previous string buffer, it just don't reduce the shared (working space buffer) string buffer.
Ok, this will free a PB internal buffer, but what is the advantage for us?
I have now created a thread for this: Add description for #Null$

_________________
Image
Why OpenSource should have a license
PureBasic-CodeArchiv-Rebirth: Git-Repository / Download -- Any help is welcome!
Manjaro Xfce x64 (Main system) :: WindowsXP/Xubuntu x86 (VirtualBox) :: PureBasic (Linux: x86/x64, Windows: x86) :: All are up to date


Top
 Profile  
Reply with quote  
 Post subject: Re: [Done] Function Space does not free memory
PostPosted: Tue Jan 15, 2019 6:21 pm 
Offline
Addict
Addict

Joined: Wed Nov 12, 2008 5:01 pm
Posts: 1050
Location: Russia
Constant #Null$ must to free string and to zero pointer, otherwise constant #Null$ does not make sense.
Code:
s.s
Debug @s
s = "12345678"
Debug @s
s = #Null$
Debug @s ; <- Must be 0.

_________________
Library XP_Menu_Lib - office menu; HID_Lib - USB Library
Torrent client - pbTorrent (source code); Create driver in PureBasic.


Top
 Profile  
Reply with quote  
 Post subject: Re: [Done] Function Space does not free memory
PostPosted: Tue Jan 15, 2019 6:32 pm 
Offline
Enthusiast
Enthusiast

Joined: Mon Dec 21, 2015 8:12 pm
Posts: 141
User_Russian wrote:
Constant #Null$ must to free string and to zero pointer, otherwise constant #Null$ does not make sense.
It does, in previous versions. But it's broken in 5.70.


Top
 Profile  
Reply with quote  
 Post subject: Re: [Done] Function Space does not free memory
PostPosted: Wed Jan 16, 2019 10:31 am 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 13612
Location: France
Ok, so it's a regression. I will look into it.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye