Memory Leak when attaching and detaching render products (4.0.0 & 2023.1.1)

There appears to be a memory leak in Isaac Sim when using the methods attach and detach for both writers and annotators. I’ve tested on both 4.0.0 and 2023.1.1.

Here is some sample code to prove the issue.

from isaacsim import SimulationApp
# from omni.isaac.kit import SimulationApp

simulation_app = SimulationApp({"headless": True})  # Option: "renderer": "PathTracing"

import omni.replicator.core as rep
import psutil

def sample_memory():
    return psutil.Process().memory_info().rss / 1024 / 1024  # in MB

writer = rep.WriterRegistry.get("BasicWriter")
writer.initialize(
    output_dir="/isaac-sim/output",
    rgb=True,
    distance_to_image_plane=True,
    normals=True,
    frame_padding=8,
)
rep_camera = rep.create.camera()
render_product = rep.create.render_product(
    rep_camera,
    resolution=(640,
                480),
    name="test_render_product"
)
for _ in range(1000):
    print(f"sample_memory = {sample_memory()}")
    writer.attach(render_product)
    writer.detach()

I’ve noticed similar behavior with annotators. I assumed this was a valid way of using render products because of this example.

https://docs.omniverse.nvidia.com/isaacsim/latest/replicator_tutorials/tutorial_replicator_ur10_palletizing.html

See the function _run_pallet_scenario.

It seems you’re experiencing a memory leak issue with the attach and detach methods in Isaac Sim. I recommend trying the latest version of Isaac Sim (4.1.0), as newer versions often include bug fixes and improvements, including those related to memory management. Updating to the most recent release could help resolve known issues and enhance overall performance.