Comment by nextaccountic

Comment by nextaccountic 2 days ago

5 replies

I mean, that's a neat tradeoff, however..

> There’s actually no ‘free’, but in the (member -> variable data) ontology of Cicada there are indeed a few ways memory can become disused: 1) members can be removed; 2) members can be re-aliased; 3) arrays or lists can be resized. In those conditions the automated/manual collection routines will remove the disused memory, and in no case is there any dangling ‘pointer’ (member or alias) pointing to unallocated memory. Does this answer your question?

Does this mean that Cicada will happily and wildly leak memory if I allocate short lived objects in a loop?

Why don't you just add some reference counting or tracing GC like everybody else

> 1) members can be removed;

Does this causes use after free if somebody had access to this member? Or it will give an error during access?

briancr a day ago

No, there are both referenced-based and tracing-based GC routines that will deallocate short-lived objects. Sorry, I was just trying to enumerate the ways memory goes out of scope to show that none of those ways results in an invalid pointer _within the scripting language_.

The safety comes because there is no way to access a pointer address within the scripting language. The main functionality of pointers is replaced by aliases (e.g. a = @b.c, a = @array[2], etc.). The only use of pointers is behind the scenes, e.g. when you write ‘b.c’ there is of course pointer arithmetic behind the scenes to find the data in member ‘b’.

Having said that, it is certainly possible for a C callback routine to store an internal pointer, then on a second callback try to use that pointer after it has fallen out of scope. This is the only use-after-free I can imagine.

  • nextaccountic a day ago

    Okay, this is the usual way to perform safe memory management in managed / high level programming languages.. it was just that your "alias" terminology threw me off

    Note that you can add multithreading later if you adopt message passing / actor model. Even Javascript, which is famously single threaded, gained workers with message passing at some point

    • briancr 20 hours ago

      Yes, multithreading seems to be a consistent theme among the comments.. so I should definitely look into that. Thanks for the comment. (I actually haven’t done much threaded programming myself so this would be a learning experience for me..)

briancr a day ago

Also, if someone else has access to the member, meaning that there is an alias to the member, then the reference count should reflect that. Here’s an example:

i :: int | 1 reference

a := @i | 2 references

remove i | 1 reference

The data originally allocated for ‘i’ should persist because its reference count hasn’t hit zero yet.

  • [removed] a day ago
    [deleted]