Skip to content

Memory leak in callback function of Upsert  #150

@rts-gordon

Description

@rts-gordon

Hi there,
I use ConcurrentMap to story symbols data, if use Upsert function, there are memory leak; if use Set function, it is fine.
Can you please take a look at this? thank you.

a.go maybe memory leak in the callback function: ExistSymbolCB

var SymbolMap camp.ConcurrentMap[string, libSymbol.GenericSymbol]
SymbolMap.Upsert(key, genSym, ExistSymbolCB)
...

func ExistSymbolCB(exists bool, valueInMap libSymbol.GenericSymbol, newValue libSymbol.GenericSymbol) libSymbol.GenericSymbol {
	if exists {
		valueInMap.Session = newValue.Session
		return valueInMap
	}
	return newValue
}

b.go, no memory leak in Set function

var SymbolMap camp.ConcurrentMap[string, libSymbol.GenericSymbol]
...

if existSym, ok := SymbolMap.Get(key); ok {
	existSym.Session = genSym.Session
	SymbolMap.Set(key, existSym)
} else {
	// new Symbol config
       SymbolMap.Set(key, genSym)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions