Hi,
I'm not sure whether I've stumbled over a bug or a feature, so I'm
curious if someone might explain that. The statement below declares
a stored procedure:
CREATE LANGUAGE PLPGSQL;
DROP TABLE memleak_test;
CREATE TABLE memleak_test (id serial);
CREATE OR REPLACE FUNCTION memleak(INTEGER) RETURNS INTEGER AS $$
DECLARE c ALIAS FOR $1; i INTEGER;
BEGINEXECUTE 'PREPARE leak AS INSERT into memleak_test values (1);'; FOR i IN 1..c LOOP EXECUTE 'EXECUTE leak;';END
LOOP;EXECUTE'DEALLOCATE leak;';
RETURN 0;
END;
$$ LANGUAGE PLPGSQL;
and that procedure, if being called repeatedly, say, as
'SELECT memleak(30000)' causes postmaster to eat memory rather noticeably,
one my machine, for example, first call to memleak(30000) eats 100M, second
50M, and the subsequent calls leak 1-3M per call.
The same leak occurs when I've tried the same code writte on plperl, so
it doesn't seem that the effect is related to plpgsql.
--
Sincerely,Dmitry Karasik