[vtkusers] vtkImageViewer memory usage
sureshj at gmail.com
Tue Aug 30 17:43:58 EDT 2011
Hi Pratik and everyone else,
I've finally gotten around to re-visiting this problem and I'm getting
some strange results.
I've taken Pratik's advice and made a test app using the JPEGReader
example inside of a Win32 app. So, I initialize/show an empty HWND,
and then separately create 3 imageViewers (linked to 3 HWNDs that I
had previously created).
My memory consumption is as follows:
After InitInstance: 14.5 MB
After 1st ImageViewer: 34.1 MB
After 2nd ImageViewer: 40 MB
After 3rd ImageViewer: 46.2 MB
*Note: this is using a test image which has a file size of 27KB,
width=400pixels, height=400pixels and a bit depth of 8.
So, according to this, my first image viewer required 20MB to create,
second and third required closer to 6MB.
I have also re-tested this using 3 different JPEGReaders as inputs to
the imageViewers and there is negligible difference. As well, I used a
3kB version of my test-image and it showed the same memory footprint.
So, does anyone know why there is this sort of discrepancy? I have
little knowledge of how the internals of the renderers and windows
work, so I'm at a loss and would appreciate any help (as well, if
there is any way for me to reduce this footprint as much as possible,
as I could have as many as 40 of these windows open at once!).
P.S. I've attached my sample code
// inside main function:
// Perform application initialization:
if (!InitInstance1 (hInstance, nCmdShow))
vtkSmartPointer<vtkJPEGReader> jpegReader =
jpegReader->SetFileName ( "D:\\Albert-Einstein.jpg" );
imageViewer = vtkSmartPointer<vtkImageViewer2>::New();
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
imageViewer->SetParentId( hWnd1 );
imageViewer1 = vtkSmartPointer<vtkImageViewer2>::New();
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor1 =
imageViewer1->SetParentId( hWnd2 );
imageViewer2 = vtkSmartPointer<vtkImageViewer2>::New();
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor2 =
imageViewer2->SetParentId( hWnd3 );
On Fri, Jun 17, 2011 at 11:25 PM, pratik <pratik.mallya.ml at gmail.com> wrote:
> You can try using this:
> as a template.
> I ran it on Debian Linux and for a 104.9kb file the process is taking 12MB
> On Saturday 18 June 2011 08:24 AM, Suresh Joshi wrote:
>> Hello everyone,
>> Although I don't want to double post and spam the list, I haven't
>> heard any responses to a question I posted on May 27th, so I'll give
>> it another shot with some updated information:
>> My question is still the same and I'm wondering why my stock
>> vtkImageViewer pipeline (quoted below) is using around 50MB of memory
>> on my Windows 7 machine. The jpeg I am displaying is 400x400 pixels.
>> Also, if I were to create a separate
>> Renderer+Window+Interactor+Mapper+etc, the memory footprint should
>> still be the same, correct?
>> Thanks everyone!
>> On Fri, May 27, 2011 at 3:06 PM, Suresh Joshi<sureshj at gmail.com> wrote:
>>> Hello all,
>>> I've done a fair bit of Googling, but haven't found many topics about
>>> In most of my applications dealing with ITK/VTK, I haven't cared too
>>> much about the memory used by the viewer, because I'd usually also
>>> have a 3D volumetric reconstruction/registration running at the same
>>> time, but for the first time I've taken note of the memory used by the
>>> viewer window itself.
>>> In a naive application (in C++ usually, but for instance in python here):
>>> reader = vtkJPEGReader()
>>> # 27kb JPEG file
>>> reader.SetFileName( "Albert-Einstein.jpg" )
>>> viewer = vtkImageViewer()
>>> viewer.SetInputConnection( read.GetOutputPort() )
>>> interactor = vtkRenderWindowInteractor()
>>> viewer.SetupInteractor( interactor )
>>> This 'program' seems to use about 50MB of memory on my Windows 7 box
>>> (with VTK 5.6). When I place these viewers (in c++) in my
>>> applications, I notice a similar usage...
>>> Now, the problem for me this time is that I need a less
>>> memory-intensive viewer, because I would like to instantiate multiple
>>> (lets say at least 10) vtkImageViewers in my app (yet, greedily, I
>>> would like to keep similar functionality, with interactions and all).
>>> So I guess I have a few questions:
>>> a) Is there any documentation anywhere discussing the memory
>>> footprints of the vtk viewers/viewports/windows/etc and discussing the
>>> best practices when it comes to keeping memory usage down?
>>> b) Is my naive approach of creating multiple vtkImageViewers the worst
>>> thing I can do (keeping in mind that it gives the exact functionality
>>> that I desire right now)?
>>> c) Should I be looking at having one renderWindow with multiple
>>> viewports instead, with one or more interactors? (And is this
>>> noticeably better?)
>>> Thanks everyone!
>> Powered by www.kitware.com
>> Visit other Kitware open-source projects at
>> Please keep messages on-topic and check the VTK FAQ at:
>> Follow this link to subscribe/unsubscribe:
More information about the vtkusers