Repository navigation
Description
Have I written custom code (as opposed to using a stock example script provided in MediaPipe)
Yes
OS Platform and Distribution
Linux Arch 7.0.10-arch1-1
MediaPipe Tasks SDK version
1.0.1
Task name (e.g. Image classification, Gesture recognition etc.)
Pose Landmark Detection
Programming Language and version (e.g. C++, Python, Java)
Python 3.14.5
Describe the actual behavior
I was moving a mediapipe program I was making on my windows desktop to my Linux laptop, I made a new virtual environment and a fresh install of mediapipe. I was starting to get a memory leak issue that caused my program to stop functioning, and I used objgraph.show_most_common_types() to see if there was a buildup of certain objects.
After a little while, there starts to be a buildup of objects of types: Landmark, NormalizedLandmark, LP_MpLandmarkC, and LP_MpNormalizedLandmarkC, all of them in the same amount.
I found a way to de-reference the results causing the Landmark and NormalizedLandmark objects in the callback function of detectAsync, which stopped them building up so much, but I can't figure out what LP_MpLandmarkC and LP_MpNormalizedLandmarkC are, nor why the garbage collector doesn't get rid of them, or how to de-reference them manually. I can't find any documentation of these data types.
Describe the expected behaviour
There should be no buildup of LP_MpLandmarkC and LP_MpNormalizedLandmarkC objects, I need a way to de-reference these excess objects or otherwise stop them building up and causing a memory leak.
Standalone code/steps you may have used to try to get what you need
import cv2
import mediapipe as mp
from mediapipe.tasks import python
import gc
import objgraph
from memory_profiler import profile
import tracemalloc
mp_pose = mp.tasks.vision.PoseLandmarker
mp_pose_options = mp.tasks.vision.PoseLandmarkerOptions
PoseLandmarkerResult = mp.tasks.vision.PoseLandmarkerResult
VisionRunningMode = mp.tasks.vision.RunningMode
class camera_settings():
def __init__(self):
self.camera_index = 0
self.camera_FPS_target = 30
def initialize_detector(camera_data):
global pose_results
pose_results = result_handler()
global cap
cap = cv2.VideoCapture(camera_data.camera_index)
cap.set(cv2.CAP_PROP_FPS, camera_data.camera_FPS_target)
cap.set(cv2.CAP_PROP_AUTOFOCUS, 0)
start_time = cv2.getTickCount()
# Define settings for pose detection
options = mp_pose_options(
base_options = python.BaseOptions(model_asset_path='pose_landmarker_lite.task'),
min_pose_detection_confidence = 0.7,
min_tracking_confidence = 0.7,
min_pose_presence_confidence = 0.7,
running_mode=VisionRunningMode.LIVE_STREAM,
# Define the callback function to run when results are acquired
result_callback=pose_results.update_result
)
return options, pose_results, cap, start_time
def cam_detection(options, pose_results, cap, start_time):
# Use the options defined earlier to initialize the pose identification
with mp_pose.create_from_options(options) as pose:
while cap.isOpened() == True:
# Get the timestamp for the start of this cycle
frame_timestamp_ms = int((cv2.getTickCount() - start_time) * 1000 / cv2.getTickFrequency())
# Read the image from the camera and store it in 'frame'
ret, frame = cap.read()
# Convert the frame from RGB to BGR color, as BGR can be read quicker
frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
# Convert the recolored frame to a mediapipe image
mp_image = mp.Image(image_format=mp.ImageFormat.SRGB, data=frame)
# detect the landmarks from the image (the callback function will run right after)
mp_pose.detect_async(pose, mp_image, frame_timestamp_ms)
gc.collect()
objgraph.show_most_common_types()
# Contains the results of the detection in Mediapipe's result structure and updates the results via the update_result callback
class result_handler():
def __init__(self):
self.result_landmarks = None
def update_result(self, result: PoseLandmarkerResult, output_image: mp.Image, timestamp_ms: int):
self.result_landmarks = result.pose_landmarks[0]
result.pose_landmarks = None
result.pose_world_landmarks = None
gc.collect()
camera_data = camera_settings()
options, result, cap, start_time = initialize_detector(camera_data)
cam_detection(options, result, cap, start_time)
Other info / Complete Logs
This is the output of objgraph.show_most_common_types(), which is run every frame. LP_MpLandmarkC and LP_MpNormalizedLandmarkC increase quickly. This issue only really started on my Linux laptop, I don't experience the memory leak on Windows.
builtin_method 36917
LP_MpNormalizedLandmarkC 19074
LP_MpLandmarkC 19074
function 18128
dict 13449
tuple 11984
list 11124
Parameter 5395
ReferenceType 4913
builtin_function_or_method 4857
Activity
Zoey-Vail commentedon Aug 30, 2026
*UPDATE
I've managed to at least figure out that LP_MpLandmarkC and LP_MpNormalizedLandmarkC exist in
c_resultvariable from theconvert_resultfunction inmediapipe/tasks/python/vision/pose_landmarker.py, and that they are pointers to MpLandmarkC and MpNormalizedLandmarkC objects, (I don't know if these pointers come up anywhere else). However I still can't figure out how to de-reference them, Everything I've attempted either did nothing or breaks the detection. I'm seriously confused as to why this issue doesn't happen on my Windows machine, but it does on Linux, at least for me.HarishPermal commentedon Sep 7, 2026
hi @Zoey-Vail
Sorry for the delay, i've been testing this on python 3.13 i didn't see any memory leaks, i think this could be a Cpython bug
Im still trying with different version of python