Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How long can memory leaks persist in RPGLE programs?

I'm putting into production some RPGLE code which uses %alloc and dealloc to allocate memory. Programmers should be able to ensure there are no resulting memory leaks but I'm worried about what happens if they don't.

My question is: if programmers mess up and there are memory leaks then when will this memory be reclaimed? Is it when the program leaves memory or when the job finishes?

like image 295
Tarquila Avatar asked Dec 23 '22 08:12

Tarquila


2 Answers

From the ILE RPG Programmer's Reference Guide:

Storage is implicitly freed when the activation group ends. Setting LR on will not free any heap storage allocated by the module, but any pointers to heap storage will be lost.

If your RPG program is in its own activation group, then the memory will be freed when the program ends. Of course, when your job ends, so does your activation group. So ending the job will always clean up any memory allocated.

like image 122
Tracy Probst Avatar answered Dec 24 '22 21:12

Tracy Probst


It sounds like you are approaching RPG from a C/C++ background. I've been programming in RPG for about 8 years now and only a handful of times ever had to use the %alloc() BIF.

That being said if you are using a new activation group, you should be fine. If you are using a named activation group and you do not issue the RCLACTGRP command or you are using the default activation group you could run into issues.

like image 22
James R. Perkins Avatar answered Dec 24 '22 22:12

James R. Perkins