On 14/10/2011 19:26, Colomban Wendling wrote:
- each time all files are closed only 200k is returned to the OS, but
since the first open uses 22.8Mb but later ones less, Geany isn't leaking all of it, it is being held by the allocators.
Geany at least keeps all the GeanyDocuments alive and tries to re-use them (document_create() at line 564). This avoids having to re-allocate the document struct everytime, though it'll then never release this memory. However, either the user won't open so much files at once or she's likely to keep having a large amount of open files, so I don't think it's a (the?) problem -- and anyway I guess the allocation would be quite small.
Exactly, 100 GeanyDocument is still small. Also we don't reuse the private document structures. The reason for caching geanydocument structs is not efficiency, but so we can inspect doc->is_valid even after a document is closed.
In hindsight I don't think this was really a good idea, but it came about mainly for backward compatibility with existing code (originally the document array was a fixed size).
At the time we could have fixed the code that relied on geanydocuments never being freed, but now I think it might be too late.
However, we'd probably better use GSlice here (for fragmentation and maybe caching), and maybe even release the memory to GSlice so it does all the management, and could even release it to the system at some point if it makes sense to it.
If we didn't need to keep geanydocuments around, I think g_slice would be Ok for this. As it is we could change the geanydocumentprivate struct to use it, but it might not help much.