#Dereferencing
1 messages · Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
Here is an AI assisted attempt to answer your question 🤖. Maybe it helps! In any case, a human is on the way 👍. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.
incorrect. Dereferencing in programming refers to the process of accessing the value stored at a memory address that is pointed to by a reference or pointer.
When an object is dereferenced, it means that the reference or pointer pointing to that object is used to access the actual object in memory. This allows the program to manipulate or retrieve data from the object.
In the example you provided, calling the .toString() method on an object does not necessarily mean that the object will be garbage collected immediately after. Garbage collection is a process in which unused objects are automatically removed from memory by the programming language's runtime system.
The garbage collection process typically occurs periodically and is triggered by certain conditions, such as when memory becomes low or when a certain threshold of unused objects has been reached. So, just because a method is called on an object does not mean that it will be immediately garbage collected.
It's important to note that different programming languages and runtime environments may have different garbage collection mechanisms and behaviors, so it's always best to consult the specific documentation for your language or platform for more information on how garbage collection works.
Hush TJ-Bot
It does say
```String text = obj.toString(); // 'obj' is dereferenced.````
So... I am unsure
dereferencing has nothinig to do with garbage collection
it basically means that it uses the "reference" obj and tries to get the actual object underneath
otherwise it can't call the method, that's what dereferencing is
You don't need to do that for a primitive because it's not a reference 🙂
Dereferencing means the action of accessing an object’s features through a reference
I just assumed something else.
yeah
so every object in java is a pointer, UNTIL you call a method on it
Then the JVM will look up where the pointer points to
That's a piece of memory on the heap
That heap memory contains a header, and then the actual data of the fields you defined in that method
With that header, Java can, at runtime, figure out which method to call, stuff like that
I don't know if I like that sentence.
Objects are... just referenced, while primitives are directly interconnected with the variable, right? So you can have multiple references to the same object but only one reference to a primitive, right?
That's why I used object in that sentence. Primitives are never references. They are just on the stack
Or in a register
I mean
UNTIL you call a method on it
Even after, they are referenced, no?
Or what do you mean by that?
yeah, but that reference doesn't have to be valid
Until you call a method on it, which is the dereferencing you're talking about
A null reference for example
Yeah, if you have any of these questions, I'll be glad to answer them 🙂
Signs you want to learn a lot 🙂
Sure, I have no doubts there are plenny more to come.
Closed the thread.