Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #39830 > unrolled thread
| Started by | "C.D. Altenburg, Ph.D," <cdalten@gmail.com> |
|---|---|
| First post | 2022-11-03 10:05 -0700 |
| Last post | 2022-11-03 19:29 -0400 |
| Articles | 5 — 4 participants |
Back to article view | Back to comp.lang.java.programmer
How do I dereference a static string "C.D. Altenburg, Ph.D," <cdalten@gmail.com> - 2022-11-03 10:05 -0700
Re: How do I dereference a static string Andreas Leitgeb <avl@logic.at> - 2022-11-03 17:38 +0000
Re: How do I dereference a static string "e.d.pro...@gmail.com" <e.d.programmer@gmail.com> - 2022-11-03 12:37 -0700
Re: How do I dereference a static string Arne Vajhøj <arne@vajhoej.dk> - 2022-11-03 20:14 -0400
Re: How do I dereference a static string Arne Vajhøj <arne@vajhoej.dk> - 2022-11-03 19:29 -0400
| From | "C.D. Altenburg, Ph.D," <cdalten@gmail.com> |
|---|---|
| Date | 2022-11-03 10:05 -0700 |
| Subject | How do I dereference a static string |
| Message-ID | <282053db-e7b9-4f0a-a66c-12f53021fd55n@googlegroups.com> |
Say I have the string public static string foo = "foo"; can I just do foo = null; in order to dereference that string?
[toc] | [next] | [standalone]
| From | Andreas Leitgeb <avl@logic.at> |
|---|---|
| Date | 2022-11-03 17:38 +0000 |
| Message-ID | <slrntm7v56.1qde.avl@logic.at> |
| In reply to | #39830 |
C.D. Altenburg, Ph.D, <cdalten@gmail.com> wrote: > Say I have the string > public static string foo = "foo"; > can I just do > foo = null; > in order to dereference that string? For what you're doing, "unreferencing" might be the better word. The word from subject "dereferencing" rather denotes access of the referenced thing, like in System.out.println(foo);
[toc] | [prev] | [next] | [standalone]
| From | "e.d.pro...@gmail.com" <e.d.programmer@gmail.com> |
|---|---|
| Date | 2022-11-03 12:37 -0700 |
| Message-ID | <240bceee-4aa9-4c13-85e7-de1946350bb4n@googlegroups.com> |
| In reply to | #39830 |
On Thursday, November 3, 2022 at 1:05:17 PM UTC-4, C.D. Altenburg, Ph.D, wrote: > Say I have the string > > public static string foo = "foo"; > > can I just do > > foo = null; > > in order to dereference that string? That depends what you mean by dereference. If you want to clear the value, sure set to null like that would work. If you mean remove the variable from memory, static values are tied to the class, you'd have to unload the class. It is still possible but not advisable to have a public static variable which is not final. It's better to make it private static and use accessor methods.
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2022-11-03 20:14 -0400 |
| Message-ID | <tk1lgv$1i5c$1@gioia.aioe.org> |
| In reply to | #39833 |
On 11/3/2022 3:37 PM, e.d.pro...@gmail.com wrote: > On Thursday, November 3, 2022 at 1:05:17 PM UTC-4, C.D. Altenburg, Ph.D, wrote: >> Say I have the string >> >> public static string foo = "foo"; >> >> can I just do >> >> foo = null; >> >> in order to dereference that string? > That depends what you mean by dereference. If you want to clear the > value, sure set to null like that would work. If you mean remove the > variable from memory, static values are tied to the class, you'd have > to unload the class. Note that: ... foo = "foo"; ... foo = null; Involves two memory locations. The variable foo that is a reference and a String object containing "foo". Arne
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2022-11-03 19:29 -0400 |
| Message-ID | <tk1itd$n9b$1@gioia.aioe.org> |
| In reply to | #39830 |
On 11/3/2022 1:05 PM, C.D. Altenburg, Ph.D, wrote: > Say I have the string > > public static string foo = "foo"; > > can I just do > > foo = null; > > in order to dereference that string? It is a valid statement. But note that Java does not use reference counting for memory management so setting references to null when "done" is very rare in Java (doing it when "ready" is seen). Arne
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web