A coworker passed a test script on to me that was failing with the following memory error:
ORA-04030: out of process memory when trying to allocate 4088 bytes (PLS CGA hp,pdzgM64_New_Link)
The error occurred when initializing a PL/SQL table variable with 7500 objects. Here is my sanitized version of the code:
CREATE OR REPLACE TYPE ARRAY_ELEMENT
AS
OBJECT
(
n1 NUMBER,
n2 NUMBER,
n3 NUMBER,
n4 NUMBER );
/
CREATE OR REPLACE TYPE MY_ARRAY
IS
TABLE OF ARRAY_ELEMENT;
/
DECLARE
MY_LIST MY_ARRAY;
BEGIN
MY_LIST := MY_ARRAY(
ARRAY_ELEMENT(1234,5678,1314,245234),
ARRAY_ELEMENT(1234,5678,1314,245234),
ARRAY_ELEMENT(1234,5678,1314,245234),
...
ARRAY_ELEMENT(1234,5678,1314,245234),
ARRAY_ELEMENT(1234,5678,1314,245234)
);
The real code had different meaningful constants for each entry in the table. Here is the error:
8004 ARRAY_ELEMENT(1234,5678,1314,245234)
8005 );
8006
8007 END;
8008 /
DECLARE
*
ERROR at line 1:
ORA-04030: out of process memory when trying to allocate 4088 bytes
(PLS CGA hp,pdzgM64_New_Link)
Elapsed: 00:02:51.31
I wrapped the error code manually so it would fit on the page.
The solution looks like this:
create table MY_OBJECTS
(
o ARRAY_ELEMENT );
DECLARE
MY_LIST MY_ARRAY;
BEGIN
MY_LIST := MY_ARRAY( );
insert into MY_OBJECTS values(ARRAY_ELEMENT(1234,5678,1314,245234));
insert into MY_OBJECTS values(ARRAY_ELEMENT(1234,5678,1314,245234));
insert into MY_OBJECTS values(ARRAY_ELEMENT(1234,5678,1314,245234));
...
insert into MY_OBJECTS values(ARRAY_ELEMENT(1234,5678,1314,245234));
insert into MY_OBJECTS values(ARRAY_ELEMENT(1234,5678,1314,245234));
insert into MY_OBJECTS values(ARRAY_ELEMENT(1234,5678,1314,245234));
commit;
SELECT o
BULK COLLECT INTO MY_LIST
FROM MY_OBJECTS;
END;
/
Here is what the successful run looks like:
8004 insert into MY_OBJECTS values(ARRAY_ELEMENT(1234,5678,1314,245234));
8005 insert into MY_OBJECTS values(ARRAY_ELEMENT(1234,5678,1314,245234));
8006
8007 commit;
8008
8009 SELECT o
8010 BULK COLLECT INTO MY_LIST
8011 FROM MY_OBJECTS;
8012
8013 END;
8014 /
PL/SQL procedure successfully completed.
Elapsed: 00:00:21.36
SQL>
There is an Oracle document about this bug:
ORA-4030 (PLSQL Opt Pool,pdziM01_Create: New Set), ORA-4030 (PLS CGA hp,pdzgM64_New_Link) (Doc ID 1551115.1)
It doesn’t have using bulk collect as a work around. My situation could be only useful in very specific cases but I thought it was worth sharing it.
Here are my scripts and their logs: zip
This is on HP-UX Itanium Oracle 11.2.0.3.
Bobby