File: fprintfLeak.m

package info (click to toggle)
psychtoolbox-3 3.0.14.20170103%2Bgit6-g605ff5c.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 103,044 kB
  • ctags: 69,483
  • sloc: ansic: 167,371; cpp: 11,232; objc: 4,708; sh: 1,875; python: 383; php: 344; makefile: 207; java: 113
file content (30 lines) | stat: -rw-r--r-- 1,288 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function fprintfLeak
% Mathworks Case ID: 319124, reported 11/23/99.
% 
% FPRINTF leaks memory, as measured by Mac OS TempFreeMem.
%
% "Thank you for reporting this bug.  I will let our development team know,
% but at this time development has stopped for the OS9 platform, so no
% patches are expected." 
% 
% Megean McDuffy
% Technical Support Engineer
% mmcduffy@mathworks.com

fprintf('This program documents a memory leak in FPRINTF. The amount of \n');
fprintf('Temporary Free Memory available through the Mac OS is reduced \n');
fprintf('by each call to FPRINTF, by approximately the length of the formatted string plus 1.\n');
fprintf('The following example prints 9 bytes, 100 times, and loses a total of about 1000 bytes.\n\n');
free0=Bytes;
tempFree0=Bytes('TempFree');
for i=1:100
	fprintf('123456789');
end
free=Bytes;
tempFree=Bytes('TempFree');
fprintf('\n\n');
fprintf('Before: %8ld free, %8ld temp free.\n',free0,tempFree0);
fprintf('After:  %8ld free, %8ld temp free.\n',free,tempFree);
fprintf('Change: %8ld free, %8ld temp free.\n',free-free0,tempFree-tempFree0);
fprintf('\nThe most likely explanation is that FPRINTF is calling the Mac Toolbox function TempNewHandle()\n');
fprintf('to allocate space for the output string, and failing to call DisposeHandle().\n');