It doesn't matter if cvReleaseImage is before cvWaitKey?
I change the order of cvReleaseImage and cvWaitKey, and it does work too.
#include "stdafx.h" int main(int argc, char** argv) { cvNamedWindow("testWindow",0); IplImage *img=cvLoadImage("E:/lena.jpg"); cvShowImage("testWindow",img); Sleep(10); cvReleaseImage(&img); cvWaitKey(0); cvDestroyWindow("testWindow"); return 0; }