Memory Leak With Observable List
I get a memory leak error on shutdown when, elements are added to an ObservableList that is set as Source for a ListBox
These are the relevant parts of the code:
These are the relevant parts of the code:
Code: Select all
//Declaration
Noesis::ObservableCollection<PlaylistFile> playlist;
//Adding of elments
playlist.Add(Noesis::MakePtr<PlaylistFile>(path.c_str(),duration));
//Element Class
class PlaylistFile : public Noesis::BaseComponent
{
public:
PlaylistFile();
PlaylistFile(std::filesystem::path path);
PlaylistFile(std::filesystem::path path, int64_t dur_s);
Noesis::String ToString() const override;
std::filesystem::path get_path();
int64_t get_duration();
private:
std::filesystem::path path;
Noesis::String name;
int64_t duration;
NS_IMPLEMENT_INLINE_REFLECTION(PlaylistFile, Noesis::BaseComponent) {
NsProp("Name", &PlaylistFile::name);
};
};
//Destruction Call
playlist.Clear();
Noesis::GUI:Shutdown();
Re: Memory Leak With Observable List
Are you able to reproduce this in one of our examples? If so, please create a ticket and send us the patch. Thanks
-
sfernandez
Site Admin
- Posts: 3008
- Joined:
Re: Memory Leak With Observable List
What is happening is that the internal vector used to store the items by the collection has allocated memory, and as the variable is created in the stack, it didn't release the vector memory yet when Shutdown is called. If you try with a collection created in the heap it should clean everything when it gets destroyed:
Code: Select all
//Declaration
Noesis::Ptr<Noesis::ObservableCollection<PlaylistFile>> playlist = Noesis::MakePtr<Noesis::ObservableCollection<PlaylistFile>>();
//Adding of elments
playlist->Add(Noesis::MakePtr<PlaylistFile>(path.c_str(), duration));
...
//Destruction Call
playlist.Reset();
Noesis::GUI:Shutdown();
Who is online
Users browsing this forum: No registered users and 3 guests