I just read that to completely free a vector, we need to do:
So I am imitating to do the same:
But we don’t have Swap() function in TVectorT. What shall we do then?
[quote]I just read that to completely free a vector, we need to do:
What’s this ‘’ after object’s name? When you have say std::vectorstd::string v; you call member functions like this: v.clear(); v.resize(), not v.resize() - such a syntax does not exist.
The fact that ‘TVector’ name is somehow related/similar to the name ‘vector’ does not mean the implementation is the same or even interface is the same. TVector is QUITE different, since it has different purpose.
So you either read a TVector’s documentation, or (if it’s not good enough) look into the code, otherwise it’s quite strange to assume that class ‘SomeFancyClass’ from library ‘A’ should have the same functions/implementation as ‘SomeFancyClass’ from a completely different library ‘B’.
Again, TVector is really different from vector. You can call Clear and it can really free the memory, but not always and you have to understand, when not.
Can I ask for the same about TChain as well.
TChain* tree = new TChain("tree");
EventData *branch = NULL;
for (Int_t i = 0; i < 100; i++)
branch = 0;
branch = NULL;
tree = NULL;
For the standard operation as such, I cannot get rid of:
possibly lost: 821,478 bytes in 16,523 blocks
Oops sorry, the post was posted at the exact same. And .Clear() along sure works for TVectorT. Thanks.
I still hope you understand the difference: std::vector is a generic container that holds objects of any type (the type has to meet some requirements/limitations of course), which is essentially a dynamic array. TVectorT is a part of the matrix package, so it’s more like a mathematical notion of vector, even if it does some allocations in a dynamic memory and can have arbitrary size (btw it can allocate its data on a stack without dynamic memory if size is small enough, in this case you can not ‘clear’ it). It’s not a replacement for the std::vector.
I see, but then is there a std::vector TObject that can be saved in TFile?
Does it tell you where the memory loss comes from?
[quote]I just read that to completely free a vector, we need to do:[/quote]This may or may not be a real gain in the end. Depending on how many iteration you code needs to go through free-ing the memory in the inner most loops can leads to decrease performance because you might later needs to reallocate the memory.
[quote]I see, but then is there a std::vector TObject that can be saved in TFile?[/quote]std::vector or std::vector<TObject*> … however in general a TClonesArray will be the most efficient TObject container.