# Using OxCaml to implement type-safe reference counting between OCaml and Python

DevFeed: [Using OxCaml to implement type-safe reference counting between OCaml and Python](<https://devfeed.tech/articles/using-oxcaml-to-implement-type-safe-reference-counting-between-ocaml-and-python-20199.md>)

Original publisher: [Read original article](<https://blog.janestreet.com/oxcaml-typesafe-reference-counting-python/>)

Author: Nicolas Trangez

Published: 2026-06-15T00:00:00Z

Content type: article

Language: en

Sources: [Jane Street](<https://devfeed.tech/sources/jane-street.md>)

Topics: [OCaml](<https://devfeed.tech/topics/ocaml.md>), [typesafety](<https://devfeed.tech/topics/typesafety.md>), [Python](<https://devfeed.tech/topics/python.md>), [atomic reference counting](<https://devfeed.tech/topics/atomic-reference-counting.md>), [Machine learning](<https://devfeed.tech/topics/machine-learning.md>)

Tags: [data-analysis](<https://devfeed.tech/tags/data-analysis.md>), [data-types](<https://devfeed.tech/tags/data-types.md>), [high-performance](<https://devfeed.tech/tags/high-performance.md>), [machine-learning](<https://devfeed.tech/tags/machine-learning.md>), [memory](<https://devfeed.tech/tags/memory.md>), [memory-management](<https://devfeed.tech/tags/memory-management.md>), [ocaml](<https://devfeed.tech/tags/ocaml.md>), [parallelism](<https://devfeed.tech/tags/parallelism.md>), [python](<https://devfeed.tech/tags/python.md>), [reference](<https://devfeed.tech/tags/reference.md>), [type-safe](<https://devfeed.tech/tags/type-safe.md>)

## AI overview

Jane Street's PyOCaml bridge can delay Python object deallocation when Python objects are represented as OCaml values, which is problematic for large data frames or scarce resources such as GPU memory. The excerpt says OxCaml extensions let library authors encode prompt deallocation in a typesafe way, allowing the compiler to rule out Python programs with these promptness problems. The approach uses explicit reference counting between Python and OCaml and draws on borrowing; the excerpt begins explaining Python's reference-counted object lifecycle but cuts off before detailing the implementation.

## Source excerpt

Jane Street is known for being an OCaml shop, but for years now Python has been our second major programming language, acting as the primary tool for data analysis and (especially importantly these days) machine learning. Most of our traders and researchers think and write in Python, even as the majority of our infrastructure is written in OCaml.