Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak in callback function of Upsert #150

Open
rts-gordon opened this issue Jan 25, 2024 · 3 comments
Open

Memory leak in callback function of Upsert #150

rts-gordon opened this issue Jan 25, 2024 · 3 comments

Comments

@rts-gordon
Copy link

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)
}
@helloteemo
Copy link

The memory leak problem is not in the concurrent-map library
Can you post the contents of your libSymbol.genericSymbol structure? Your statement in a.go: valueInmap.session = newValue.session replaced the session, or used the old value, which may cause the newsValue not to be recognized by garbage collection, (the session pointer may refer to GenericSymbol)

@rts-gordon
Copy link
Author

@helloteemo

Thanks for your response. There is the GenericSymbol structure:

type GenericSymbol struct {
	Symbol     string         `json:"symbol,omitempty"`
	Securities string         `json:"securities,omitempty"`
	Session    []QuoteSession `json:"session,omitempty"`
	HolidayCount int `json:"holidayCount,omitempty"`
	Holiday []int64 `json:"holiday,omitempty"`
}

The are many GenericSymbol will be updated with new Session and Holiday. I wondering why it will occur memory leak.

@helloteemo
Copy link

@helloteemo

Thanks for your response. There is the GenericSymbol structure:

type GenericSymbol struct {
	Symbol     string         `json:"symbol,omitempty"`
	Securities string         `json:"securities,omitempty"`
	Session    []QuoteSession `json:"session,omitempty"`
	HolidayCount int `json:"holidayCount,omitempty"`
	Holiday []int64 `json:"holiday,omitempty"`
}

The are many GenericSymbol will be updated with new Session and Holiday. I wondering why it will occur memory leak.

Sorry, I can't give an accurate answer, this doesn't seem to cause a memory leak

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants