Tool or function to monitor the memory consuption of variants and comobjects
I would like to know if there exists any tool (like a profiler), or a Windows function, to monitor how much memory is used by 开发者_开发知识库a particular COM object.
For example:
var
WordApplication, WordDocument: Variant;
begin
WordApplication := CreateOleObject('Word.Application');
WordDocument := WordApplication.Documents.Add;
//here I would like to know how much memory is used by
//the WordApplication and WordDocument variables.
end;
In general there could be no such tool. For such a tool to exist it would need to know about the internals of any general COM object and I think that's too much to ask.
In this example, WordDocument
is part of WordApplication
and so the memory use for the application is somewhat more pertinent. What you could do is work out how much memory the instance of Word that hosts WordApplication
is consuming. Process Explorer will tell you that.
Memory profilers exists, but inspecting the internals of applications beyond your control may be difficult, because usually you need debug symbols and/or instrumenting to let a tool to know when and for what object memory was allocated (AFAIK MS offers "checked builds" of Windows, but not Office). It is true that COM type library and intercepting standard APIs could help - try to download the trial of a tool like AQTime and see if it could help you - I never tried to use it such a way.
The closest you are likely to get is to carefully remove other sources of interference, and use the Performance Monitor in windows, while running on a very quiet virtual machine.
Watch and Log memory usage by process, over time, for Word, and your process. Watch your test runs, and review the recorded information in performance monitor. You will probably be making some assumptions that you can't prove (Example of such an unverifiable assertion: the 150K increase in WORD memory usage was 100% caused by the call to ComObject.Document.DoSomething, that you just did).
精彩评论