Example:
Int main () {iplimage * src = cvloadimage ("lena.bmp", 0); iplimage * DST = myfun (SRC); cvnamedwindow ("src "); cvnamedwindow ("DST"); cvshowimage ("src", Src); cvshowimage ("DST", DST); cvwaitkey (-1); cvreleaseimage (& SRC ); cvreleaseimage (& DST); cvdestroyallwindows (); Return 0;} iplimage * myfun (iplimage * IMG) {iplimage * src = IMG; iplimage * DST = cvcreateimage (getcvsize (SRC ), 8, 1); int I, j; for (I = 0; I <Src-> height; I ++) for (j = 0; j <Src-> width; j ++) cvset2d (DST, I, j, cvget2d (SRC, I, j); Return DST ;}
There are a total of two structs with storage space (SRC in main and DST applied in myfun), and the rest are just a pointer to the address
The storage space of these two structs is released in main.
[The release of DST space in myfun cannot be in myfun, because it will be returned for display in the main function. As long as you know the address (recorded by DST in main), you can release it after it is displayed in main]