manipulation of a reference counte
BlitzMax Forums/BlitzMax Programming/manipulation of a reference counte
| ||
| is there a way to manually manipulate the reference counter for an object? i would like to store a pointer to an object and have it not released if it the original object is set to null (or goes out of scope) and a pointer to it is still stored. ie.
Type test
Method testret:String()
Return "testing"
EndMethod
EndType
Local temp1:test=New test
' want to manually increment the counter
Local temp2:test Ptr=Varptr(temp1)
DebugLog(temp1.testret())
DebugLog(temp2[0].testret())
DebugLog("---")
temp1=Null
FlushMem
' boom. if the counter was incremented i could continue on
DebugLog(temp2[0].testret())
|
| ||
| you can't set an object to null it is only released if no more reference exist. so don't use var ptr or create a handling list for the own defined type from which you remove it manually when it shall be deleted :) |
| ||
| Doesn't it keep the object automatically if you have a pointer variable pointing to it? |
| ||
| No it isn't pointers are unmanaged, only references are managed. Strict 'test app for ref count on pointers Type test Field bla:String End Type Local a:test = New test Local b:test Ptr a.bla = "good morning" b = Varptr a Print a.bla a = Null FlushMem Print b[0].bla Delay 2000 End |
| ||
| @Dreamora - thx. thats what i was afraid of... love the garbage collection, but when you want total control its kinda annoying :( |