Skip to content

Wrappers are flawed (gmod internal?) #407

@ghost

Description

The current wrapping system creates two tables, sensitive2sf and sf2sensitive, these tables have weak values and keys respectively, because of the way Starfall does caching by doing sensitive2sf[value] = tbl (line 260 in sflib.lua) I believe that the two weak tables 'reinforce' each other, thus never marking wrapped objects for garbage collection properly. (when they should)

It seems that this is most noticeable when using structs that have a 'non-absolute' index, such as, you can have two or more keys that are Vector( 1, 1, 1 ) in a table, as those are userdata values with each their own memory address; but it's not to say that basically everything is memory-leaked with the current code, but it isn't as noticeable with some wrapped objects due to their 'absolute' index, making it so that the cache value is overridden. (for example entity wrapping).

At first I thought this could not have possibly been the issue, how can it be this flawed?
But then I tried commenting out line 260 in sflib.lua (--sensitive2sf[value] = tbl) and setting the __mode of sf2sensitive to kv, and all the memory-related issues disappeared.

An example of this flaw in action:

if not SERVER then return end

hook.add( "think", "mem_overflow", function()
    for i=1, 4096 do
        v=Vector( 1, 2, 3 )
    end
end )

P.S. Excuse my incorrect terminology.

EDIT: This seems to be an internal issue? The tables are printing blank but garbage isn't collected properly.

P.P.S Please check the issue report on thegrb93/StarfallEx before asking questions to avoid asking ones that have already been asked/answered.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions