<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/tracking-the-reference-count-of-a-gstminiobject-using-gdb-ib2pq3mfs" -->

---
title: Tracking the reference count of a GstMiniObject using gdb
description: A practical walkthrough for tracking reference count changes on GstMiniObject instances using gdb watchpoints. The technique involves setting a hardware...
canonical: https://daily.dev/posts/tracking-the-reference-count-of-a-gstminiobject-using-gdb-ib2pq3mfs
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Tracking the reference count of a GstMiniObject using gdb | daily.dev
og:description: A practical walkthrough for tracking reference count changes on GstMiniObject instances using gdb watchpoints. The technique involves setting a hardware...
og:url: https://daily.dev/posts/tracking-the-reference-count-of-a-gstminiobject-using-gdb-ib2pq3mfs
og:image: https://api.daily.dev/og/posts/ib2pq3MFs.png
og:image:alt: Tracking the reference count of a GstMiniObject using gdb
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Tracking the reference count of a GstMiniObject using gdb

**[Collabora Blog](https://daily.dev/sources/collabora)** · 6 min read · 0 upvotes · 0 comments

## Summary

A practical walkthrough for tracking reference count changes on GstMiniObject instances using gdb watchpoints. The technique involves setting a hardware watchpoint on the refcount field with `watch -location ((GstMiniObject*)caps)->refcount`, then using gdb's `commands` block to automatically print a full backtrace and continue execution on every ref/unref. Logging is enabled with `set logging on` and pagination disabled to capture the full output to gdb.txt. Also covers rebuilding without compiler optimizations (`-g3 -ggdb3 -O0`) when watchpoints report optimized-out values, and an alternative approach using conditional breakpoints on `gst_mini_object_ref`/`gst_mini_object_unref` filtered by object address.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.collabora.com/about-us/blog/2015/04/13/tracking-the-reference-count-of-a-gstminiobject-using-gdb>

## Questions this post answers

### How do I get a stack trace every time a GstMiniObject's refcount changes in gdb?

Set a hardware watchpoint on the refcount field with `watch -location ((GstMiniObject*)caps)->refcount`, then attach a commands block: `commands`, `bt`, `continue`, `end`. The `-location` flag makes gdb watch the actual memory address rather than the local variable scope, so it keeps firing even after the variable goes out of scope. Enable logging first with `set logging on` and `set pagination off` to capture all output to gdb.txt.

_Developers hunting GStreamer memory leaks share techniques like this on daily.dev._

### Why does gdb say 'value has been optimized out' for my watchpoint and how do I fix it?

The compiler has optimized away the variable, making it inaccessible to gdb. Rebuild the application and its libraries without optimization by running `make clean` followed by `make` with `CFLAGS="-g3 -ggdb3 -O0"`. The `-O0` flag disables all optimizations, while `-g3` and `-ggdb3` maximize debug symbol output, giving gdb full visibility into memory locations.

_Teams debugging native multimedia stacks track build and tooling tips like this on daily.dev._

## Similar posts on daily.dev

- [GDB source-tracking breakpoints](https://daily.dev/posts/gdb-source-tracking-breakpoints-lyedkhihx) · Fedora Magazine · 0 upvotes · 0 comments
- [Underappreciated builtin: Grand Unified Debugger](https://daily.dev/posts/underappreciated-builtin-grand-unified-debugger-fr0couz9i) · Lobsters · 0 upvotes · 0 comments
- [Nix wrote half of my debugger](https://daily.dev/posts/nix-wrote-half-of-my-debugger-gnc47givc) · Farid Zakaria’s Blog · 0 upvotes · 0 comments

---

[View this post on daily.dev](https://daily.dev/posts/tracking-the-reference-count-of-a-gstminiobject-using-gdb-ib2pq3mfs)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Tracking the reference count of a GstMiniObject using gdb","url":"https://daily.dev/posts/tracking-the-reference-count-of-a-gstminiobject-using-gdb-ib2pq3mfs","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/tracking-the-reference-count-of-a-gstminiobject-using-gdb-ib2pq3mfs"},"datePublished":"2026-08-11T08:54:09.335Z","dateModified":"2026-08-11T09:23:22.261Z","description":"A practical walkthrough for tracking reference count changes on GstMiniObject instances using gdb watchpoints. The technique involves setting a hardware...","image":"https://media.daily.dev/image/upload/s--OHB84bZF--/f_auto/v1722860399/public/Placeholder%2010","thumbnailUrl":"https://media.daily.dev/image/upload/s--OHB84bZF--/f_auto/v1722860399/public/Placeholder%2010","isAccessibleForFree":true,"articleSection":"Collabora Blog","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Collabora Blog","logo":"https://media.daily.dev/image/upload/s--ZGZ0FjqS--/f_auto,q_auto/v1786438306/logos/collabora?_a=BAMAMicg0","url":"https://daily.dev/sources/collabora"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/tracking-the-reference-count-of-a-gstminiobject-using-gdb-ib2pq3mfs","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"","timeRequired":"PT6M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Collabora Blog","item":"https://daily.dev/sources/collabora"},{"@type":"ListItem","position":3,"name":"Tracking the reference count of a GstMiniObject using gdb"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/tracking-the-reference-count-of-a-gstminiobject-using-gdb-ib2pq3mfs#faq","mainEntity":[{"@type":"Question","name":"How do I get a stack trace every time a GstMiniObject's refcount changes in gdb?","acceptedAnswer":{"@type":"Answer","text":"Set a hardware watchpoint on the refcount field with `watch -location ((GstMiniObject*)caps)->refcount`, then attach a commands block: `commands`, `bt`, `continue`, `end`. The `-location` flag makes gdb watch the actual memory address rather than the local variable scope, so it keeps firing even after the variable goes out of scope. Enable logging first with `set logging on` and `set pagination off` to capture all output to gdb.txt. Developers hunting GStreamer memory leaks share techniques like this on daily.dev."}},{"@type":"Question","name":"Why does gdb say 'value has been optimized out' for my watchpoint and how do I fix it?","acceptedAnswer":{"@type":"Answer","text":"The compiler has optimized away the variable, making it inaccessible to gdb. Rebuild the application and its libraries without optimization by running `make clean` followed by `make` with `CFLAGS=\"-g3 -ggdb3 -O0\"`. The `-O0` flag disables all optimizations, while `-g3` and `-ggdb3` maximize debug symbol output, giving gdb full visibility into memory locations. Teams debugging native multimedia stacks track build and tooling tips like this on daily.dev."}}]}
```

