Android Question Erels 'Code modules and classes': returns a deleted list-item?

Pflichtfeld

Active Member
Licensed User
In Erels helpful videos there is in above mentioned video at 7:14 there is a point I do not understand:
erel.jpg

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?
 

Pflichtfeld

Active Member
Licensed User
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.
So the pointer is removed from the list (16), but the objekt still lives on?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
(It seems do be not the same: 'reference' and 'pointer to that object'?)
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
Top