Pflichtfeld Active Member Licensed User Mar 28, 2020 #1 In Erels helpful videos there is in above mentioned video at 7:14 there is a point I do not understand: sub Pop returns the last item of a list. As I understand, what happens is: line 15: res is filled with a pointer to the last listitem line 16: this item is removed from the list line 17: now res is expected to point to nothing, but it does not. Why does this code work?
In Erels helpful videos there is in above mentioned video at 7:14 there is a point I do not understand: sub Pop returns the last item of a list. As I understand, what happens is: line 15: res is filled with a pointer to the last listitem line 16: this item is removed from the list line 17: now res is expected to point to nothing, but it does not. Why does this code work?
Erel B4X founder Staff member Licensed User Longtime User Mar 29, 2020 #2 17: No, it can never happen that you have a dangling pointer. The object will only be garbage collected when there are no references to it. As long as you can reach the object in some way, its memory will not be released. Upvote 0
17: No, it can never happen that you have a dangling pointer. The object will only be garbage collected when there are no references to it. As long as you can reach the object in some way, its memory will not be released.
Pflichtfeld Active Member Licensed User Mar 29, 2020 #3 Erel said: 17: No, it can never happen that you have a dangling pointer. The object will only be garbage collected when there are no references to it. As long as you can reach the object in some way, its memory will not be released. Click to expand... So the pointer is removed from the list (16), but the objekt still lives on? Upvote 0
Erel said: 17: No, it can never happen that you have a dangling pointer. The object will only be garbage collected when there are no references to it. As long as you can reach the object in some way, its memory will not be released. Click to expand... So the pointer is removed from the list (16), but the objekt still lives on?
Erel B4X founder Staff member Licensed User Longtime User Mar 29, 2020 #4 We aren't really talking about pointers here. The object is removed from the list however it is still alive as the local 'res' variable holds a reference to that object. Upvote 0
We aren't really talking about pointers here. The object is removed from the list however it is still alive as the local 'res' variable holds a reference to that object.
Pflichtfeld Active Member Licensed User Mar 29, 2020 #5 Thanks Erel! (It seems do be not the same: 'reference' and 'pointer to that object'?) Upvote 0
Erel B4X founder Staff member Licensed User Longtime User Mar 29, 2020 #6 Pflichtfeld said: (It seems do be not the same: 'reference' and 'pointer to that object'?) Click to expand... The context is different. Pointer is a C / C++ term and it is a low level feature. The pointer is the actual memory address. Reference (not C++ reference) is a bit more ambiguous and higher level concept. You hold a reference to an object. You don't know the memory address and you aren't responsible for managing the memory yourself. From the developer perspective the variable holds the object the only thing that you need to remember is that the object is never copied. Upvote 0
Pflichtfeld said: (It seems do be not the same: 'reference' and 'pointer to that object'?) Click to expand... The context is different. Pointer is a C / C++ term and it is a low level feature. The pointer is the actual memory address. Reference (not C++ reference) is a bit more ambiguous and higher level concept. You hold a reference to an object. You don't know the memory address and you aren't responsible for managing the memory yourself. From the developer perspective the variable holds the object the only thing that you need to remember is that the object is never copied.