Is it best to instantiate a new "preset" object?

Started by wcompton

Hey Steve,
I have a coding question. I am working on an application (not a synth, geared more towards music notation) that will need to load "presets" similar to the way a synth does. Currently, in the code, I have an "application" object that stores various application settings as well as a heap allocated "preset" object (created using a call to new). My question is, is it best practice to call delete every time a new preset is loaded into the application and re-create the preset object completely or is it better to keep the same preset object (maybe even make it a singleton), and load the new preset data into the existing object? I'm currently taking the first approach and the code is getting rather hard to follow, trying to keep up with what other objects contain a pointer to the preset object and how those pointers will be updated when the old object is deleted. I'm in C++/Qt. Any input would be appreciated. Thanks!

  • Will

you're probably better off asking somewhere such as stackoverflow, as I don't want to get dragged in to your memory management woes :) But of course you want to free memory one way or another (i.e. load, pointer swap, free the old memory contents).