Oxygen Basic
Programming => Problems & Solutions => Topic started by: pber on July 01, 2014, 05:33:39 AM
-
I can not entirely free instances of this class.
class IFunction
string id
sys address
[b] declare function ptr f()[/b]
method toString() as string
return "f:" id "<" address ">"
end method
method constructor(id0 as string, sys addr0)
initialize id0,addr0
end method
method destructor()
frees this.id
frees this.address
end method
method initialize(id0 as string, sys addr0)
id =id0
address =addr0
end method
method call()
@f=address
f()
end method
end class
I suspect the function-pointer declaration allocates
some global memory at each instance creation.
Memory I can not free in the destructor.
-
Hi Paolo,
frees is required only for deallocating bstrings.
Oxygen strings are always automatically garbage-collected.
Therefore in your example, the destructor has nothing to do. But after calling the destructor, del will deallocate memory allocated to the object itself and set the object pointer to 0.
Test:
class IFunction
string id
sys address
declare function ptr f()
method toString() as string
return "f:" id "<" address ">"
end method
method constructor(id0 as string, sys addr0)
initialize id0,addr0
end method
method destructor()
end method
method initialize(id0 as string, sys addr0)
id =id0
address =addr0
end method
method call()
@f=address
f()
end method
end class
function f1() as sys, label
print "here"
end function
new Ifunction fn("ABC",@f1)
print fn.toString
fn.call
del fn
print @fn '0
PS: the new and del macros:
def new 1 %1 * %2 : @%2=getmemory sizeof %1 : %2.constructor
def del 1 %1.destructor : freememory @%1 : @%1=0
PS: Leeks
national vegetable for Wales :)
(http://thegardenguide.typepad.com/.a/6a00e5524801f388340148c8761265970c-500wi)
-
A soup of leeks, potatoes and celery
and I feel like a king.
...well: I know it was a non-sense trying to free local strings.
But in effect it recuces the memory leack.
Anyway: no, still loosing memory.
Maybe I use the wrong test method (even if for other classes
it registers no leacks at all). It's not a great tool: I use sysinternals processExplorer.
Which tool do you use to test memory usage?
-
Which tool do you use to test memory usage?
Under Windows, if I start getting messages saying I've exhausted resources and my mouse hops around the screen, it's a clue for me that something is wrong. Then again it's Windows so maybe not. REBOOT tends to give a second chance to watch it happen all over again.
-
Under Windows
I know: the win logo at startup is there to alert something is wrong (or it will be shortly).
-
Can you imagine the money Microsoft could have made on virus protection? Those pop-ups that won't let you do any else until you buy a fix malware marketing campaigns would have netted a fortune. Missed opportunities. :-X
-
Yes, I see the memory leak (in Windows Task Manager) when creating and deleting instances of Ifunction many times.
For every instance, The id string is logged onto the global garbage list which is not emptied till the end of the program. Not much help for this mode of OOP.
The cleanest solution is to make id a bstring, then free it explicitly in the destructor, like you did before.
class IFunction
bstring id
sys address
declare function ptr f()
method toString() as string
return "f:" id "<" address ">"
end method
method constructor(id0 as string, sys addr0)
initialize id0,addr0
end method
method destructor()
frees id
end method
method initialize(id0 as string, sys addr0)
'method initialize(string id0, sys addr0)
#show id =id0
address =addr0
end method
method call()
@f=address
f()
end method
end class
function f1() as sys, label
'print "here"
end function
print "start"
string s
for i=1 to 1000000
new Ifunction fn("ABC",@f1)
s=fn.toString
fn.call
del fn
next
print @fn '0
PS: Wikileaks :)
(http://www.globalpost.com/sites/default/files/imagecache/gp3_full_article/julian_assange_statement_ecuador_embassy_20120819_1.jpg)
If Julian Assange steps out of the Equadorian embassy, these chaps will arrest him immediately. The siege has cost 10 million pounds so far! Someone must be desperate.
-
For every instance, The id string is logged onto the global garbage list which is not emptied till the end of the program. Not much help for this mode of OOP.
The cleanest solution is to make id a bstring, then free it explicitly in the destructor, like you did before.
Thanks again Charles,
this way it's just a matter of memory licks :P
-
SB hangs on to allocated memory for reuse and releases everything in the end. You can UNDEF a variable to release the memory assigned. Memory / string management is an art in itself.
Q. How much memory has to leak before becoming a pool?
-
A leak in Brussels:
(http://download.vikidia.org/vikidia/fr/images/8/83/2005_manneke_pis05.jpg)
And finally, a cheerful lick:
(http://i1117.photobucket.com/albums/k597/xxKyraRocks/screen_lick.gif)
;D
-
...this way the pool will be filled slowly, but certainly.
hi Mike
-
Hi Paolo!
A soup of leeks, potatoes and celery and I feel like a king.
Does cipolla zuppa contain potato and/or celery? I always thought it contains only onions and water. :D
SB hangs on to allocated memory for reuse and releases everything in the end. You can UNDEF a variable to release the memory assigned. Memory / string management is an art in itself.
Not only in the end, John. If you're using its sources embedded in, say, a C program, you can also allocate and free (i.e. manage) entire thread memory pools using the API that Peter provided for that purpose.
Q. How much memory has to leak before becoming a pool?
A. As you can see, sometimes pools are provided to avoid leaks. :)
-
leeks are not onions!
Mike: the taste is similar,
but color and form ... :-[
...I want to taste white russia cooking, but not too soon ::)
-
(http://www.belta.by/newnimages/001098_00000665451.jpg)
Click here for more! (https://www.google.by/search?q=%D0%B1%D0%B5%D0%BB%D0%BE%D1%80%D1%83%D1%81%D1%81%D0%BA%D0%B0%D1%8F+%D0%BD%D0%B0%D1%86%D0%B8%D0%BE%D0%BD%D0%B0%D0%BB%D1%8C%D0%BD%D0%B0%D1%8F+%D0%BA%D1%83%D1%85%D0%BD%D1%8F&client=firefox-a&hs=Ves&rls=org.mozilla:ru:official&channel=sb&tbm=isch&tbo=u&source=univ&sa=X&ei=doGzU8i4O8TYOqnfgMgD&ved=0CCoQsAQ&biw=1348&bih=714) ;D
(Belarus is neither "white russia" nor "weiß russland". This is all Muscovite propaganda. Belarusians were around long before Moscow was built by the offsprings of the Mongol hordes. Belarusian princes were the backbone of the Grand Duchy of Lithuania and the Magdeburg Law - Europe's first constitution ever - was written in the Belarusian language)
-
Damn, that looks good!
You could take on Bubba Burgers with Belarus Bowls. ;D
-
A. As you can see, sometimes pools are provided to avoid leaks.
Correct answer.
-
It's all clean now. European contituent laws
(first of all Italian one)
are written in languages we find some difficult on reading on.
all of my memory liking to Belarus people, history and cooking :)