ID:150205
 
I am making a data structure which owns a list of text
members each associated with another structure I created.

I'm guessing my associations would be stored by reference
unless I used new. The text members would be passed by
value. (Read: the compiler yelled at me for using new.)
Please correct me if this is wrong.

When my data structure is destroyed, I want the text
members and the associations destroyed. I'm guessing I'll
need to delete associations in my Del() proc. What about
the text? Are text (or basic structures like num) members
deleted when deleting a list?

(Newbie disclaimer: I've read the faq, guide, multiple
tutorials, searched the forum for things with list and
text in the topic, and read those along with random
other posts. My apologies if I missed something.)

Thank you.
ACWraith wrote:
I am making a data structure which owns a list of text
members each associated with another structure I created.

I'm guessing my associations would be stored by reference
unless I used new. The text members would be passed by
value. (Read: the compiler yelled at me for using new.)
Please correct me if this is wrong.

When my data structure is destroyed, I want the text
members and the associations destroyed. I'm guessing I'll
need to delete associations in my Del() proc. What about
the text? Are text (or basic structures like num) members
deleted when deleting a list?

(Newbie disclaimer: I've read the faq, guide, multiple
tutorials, searched the forum for things with list and
text in the topic, and read those along with random
other posts. My apologies if I missed something.)

From what I know of DM's memory system, all object/text references within a list will be destroyed along with the list itself, including associations. Objects within the list will be deleted if their reference count goes to zero; if you want to force their deletion, you'll have to delete them manually. I usually override Del() anyway to do this because I think it's cleaner and can avoid messes with garbage collection and whatnot.

Lummox JR
ACWraith wrote:
I am making a data structure which owns a list of text
members each associated with another structure I created.

I'm guessing my associations would be stored by reference
unless I used new. The text members would be passed by
value. (Read: the compiler yelled at me for using new.)
Please correct me if this is wrong.

I don't quite understand the situation, but if you post some code I can give you my input. In a nutshell, everything in DM is passed by value; however, it's just that most of the values are references. All datums/atoms are references, including the psuedo-datum /list type. Even text strings are just references to a global database of strings used in the code, although fortunately you don't ever have to allocate them and can thus treat them just like numerical types. DM has no concept of the & reference operator in C, so you can't pass an object into a proc and expect to reassign it; you can however, change its vars (or, in the case of lists, its list elements). Here is a slightly related discussion: Objects & References.

When my data structure is destroyed, I want the text
members and the associations destroyed. I'm guessing I'll
need to delete associations in my Del() proc. What about
the text? Are text (or basic structures like num) members
deleted when deleting a list?

As LummoxJR said, DM will automatically garbage-collect unreferenced elements, like text strings and objects. So if an object is deleted, you don't have to worry about cleaning up after it, unless you have some self- or cyclical-references that the garbage-collector can't follow.

(Newbie disclaimer: I've read the faq, guide, multiple
tutorials, searched the forum for things with list and
text in the topic, and read those along with random
other posts. My apologies if I missed something.)

Nope, great post! If only all new users were so researched :)
In response to Tom
Thank you. I think I understand now.

I can use new to initialize the list in my structure if I
don't want to refer to another list. If I'm worried about
other procs messing with the members and associations they
donate then I can use new when I add them.

If I have the need to stop other procs from using the list,
the members, or the associations after deletion, then I can
use del on any of those things in the Del() proc for my
structure. If I want other procs to continue to use my
structure after deletion, I set the structure's src to null
in the Del() proc.

Little elves will take care of memory.

The original structure I mentioned has been ditched, but
I've found this information helpful for my overall
understanding. Thanks :)