Here's an extract from Blitz runtime doc:
Future's starting here and now!
So I'd suggest to add a new command named Delete which sets all vars pointing to an object to Null, calls the Delete method inside the object and releases the object's memory.
For example:
I know the BMX reference counting system stores only how many vars are pointing to an object and not the addresses of all of them.
But I think with some tricks you still can add this command:
Each BMX object has a hidden field used by GC which stores how many vars are pointing to it; if this field reaches 0 the object is removed by GC.
I guess this field is a system integer (32bit), but I think there are never 2^32 = 4,294,967,296 vars pointing to it, so I suggest to use the last bit to store a special boolean value storing whether the object has already removed or is still used.
So Delete has only two things to do:
1.: Call Method Delete() inside the object.
2.: Set the special 'object is removed bit' to true.
But than there's the question "When is the object's memory released?"
Well; each time accessing an object var the program checks whether the object's special bit is set or not; if true it'll set this var to Null and decrements the object's hidden field; so the object will be found by GC as soon the hidden field reaches 0 and it will delete it like each other object, -well, not really:
If the object's special bit is set to true the GC doesn't call the object's Delete() method because the Delete command already called it.
Here's another example:
___________________________________________
So, how do you think about it?
Any comments?
Keyword Delete Description Reserved for future expansion. Example Rem Reserved for future expansions. End Rem
Future's starting here and now!
So I'd suggest to add a new command named Delete which sets all vars pointing to an object to Null, calls the Delete method inside the object and releases the object's memory.
For example:
Strict Local obj1:class = New class Local obj2:class = obj1 If obj1 = Null Print "obj1 = Null" 'This line is not printed EndIf If obj2 = Null Print "obj2 = Null" 'This line is not printed EndIf Delete obj1 'delete this object and set obj1 and obj2 to Null. If obj1 = Null Print "obj1 = Null" 'This line is printed EndIf If obj2 = Null Print "obj2 = Null" 'This line is printed EndIf Type class EndType
I know the BMX reference counting system stores only how many vars are pointing to an object and not the addresses of all of them.
But I think with some tricks you still can add this command:
Each BMX object has a hidden field used by GC which stores how many vars are pointing to it; if this field reaches 0 the object is removed by GC.
I guess this field is a system integer (32bit), but I think there are never 2^32 = 4,294,967,296 vars pointing to it, so I suggest to use the last bit to store a special boolean value storing whether the object has already removed or is still used.
So Delete has only two things to do:
1.: Call Method Delete() inside the object.
2.: Set the special 'object is removed bit' to true.
But than there's the question "When is the object's memory released?"
Well; each time accessing an object var the program checks whether the object's special bit is set or not; if true it'll set this var to Null and decrements the object's hidden field; so the object will be found by GC as soon the hidden field reaches 0 and it will delete it like each other object, -well, not really:
If the object's special bit is set to true the GC doesn't call the object's Delete() method because the Delete command already called it.
Here's another example:
Strict Local obj1:class = New class 'The object's hidden field is now set to 00000000 00000000 00000000 00000001 because there's one var pointing to it (obj1). Local obj2:class = obj1 'Now it's set to 00000000 00000000 00000000 00000010 because there're two vars pointing to it (obj1 and obj2). If obj1 = Null Print "obj1 = Null" 'This line is not printed EndIf If obj2 = Null Print "obj2 = Null" 'This line is not printed EndIf Delete obj1 'Now the hidden field is set to 10000000 00000000 00000000 00000010 because there're two vars pointing to it, but the object is already removed. 'The two object vars are not really set to Null because the Delete command doesn't know the addresses of them. 'Before any code's executed the program checks whether the object's special bit's set or not If obj1 = Null 'It'll notice that it's set to true so it'll set obj1 to Null and decrements the object's hidden field 'The hidden field is now 10000000 00000000 00000000 00000001; obj1 is Null, so (obj1 = Null) is true and the If block is executed Print "obj1 = Null" 'This line is printed EndIf 'Before any code's executed the program checks whether the object's special bit's set or not If obj2 = Null 'It'll notice that it's set to true so it'll set obj1 to Null and decrements the object's hidden field 'The hidden field is now 10000000 00000000 00000000 00000000; obj2 is Null, so (obj2 = Null) is true and the If block is executed 'But here the GC notices this object with no var pointing to it and releases the object's memory. Print "obj2 = Null" 'This line is printed EndIf Type class EndType
___________________________________________
So, how do you think about it?
Any comments?