PHPackages                             talkinnl/dont-leak - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. talkinnl/dont-leak

ActiveLibrary[Testing &amp; Quality](/categories/testing)

talkinnl/dont-leak
==================

Safely cleans all own Test properties to prevent phpunit memory leaks

v1.0.1(2y ago)01.1kMITPHPPHP &gt;=8.2

Since Apr 4Pushed 1y ago1 watchersCompare

[ Source](https://github.com/talkinnl/dont-leak)[ Packagist](https://packagist.org/packages/talkinnl/dont-leak)[ RSS](/packages/talkinnl-dont-leak/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (1)Versions (3)Used By (0)

Don't Leak
==========

[](#dont-leak)

[![PHP Composer and unittest](https://github.com/talkinnl/dont-leak/actions/workflows/php.yml/badge.svg)](https://github.com/talkinnl/dont-leak/actions/workflows/php.yml)

---

ARCHIVED, NO LONGER NEEDED.
---------------------------

[](#archived-no-longer-needed)

This package is no longer needed, since PHPUnit now destructs the TestCase instances during the run.

- Initial PR by Sebastian 🔥 , [PR 5861](https://github.com/sebastianbergmann/phpunit/pull/5861), released in PHPUnit [10.5.21 / 11.2.2](https://github.com/sebastianbergmann/phpunit/releases/tag/10.5.21).
- Final PR by me 😎 , [PR 5875](https://github.com/sebastianbergmann/phpunit/pull/5875#issuecomment-2179933860), released in PHPUnit [10.5.23 / 11.2.4](https://github.com/sebastianbergmann/phpunit/releases/tag/10.5.23)

---

PHPUnit keeps all Test instance in memory for the whole run. This causes used memory to continuously increase, unless you clean up all your properties during a tearDown().

There's No Doubt you'll eventually forget this tedious task.

Installation
------------

[](#installation)

```
composer require --dev talkinnl/dont-leak
```

Usage
-----

[](#usage)

In your Test classes, add this as a **very last line** of your tearDown().

Maybe you'd like to always use a common parent class so you'll never forget.

```
    protected function tearDown(): void
    {
        // Start with some of your cleanups which are still needed.
        // Maybe removing files made during the test etc

        // Always call your parents; they might get worried. :)
        parent::tearDown();

        // Unset any properties, prevent memory leaks.
        DontLeak::freeOwnProperties($this);
    }
```

What does it do?
----------------

[](#what-does-it-do)

`DontLeak::freeOwnProperites($object)` unsets all properties reachable in your own scope of given $object, and all private properties of parent objects.

Properties defined by PHPUnit WON'T be touched.

What's next
-----------

[](#whats-next)

I'd really like it if this package would be become obsolete thanks to PHPUnit changing the behaviour.

Please read, and maybe vote --&gt; [sebastianbergmann/phpunit#4705](https://github.com/sebastianbergmann/phpunit/issues/4705)

Credits
-------

[](#credits)

Many suggestions of a tearDown which uses reflection to clean up exist scattered across Stack Overflow, Reddit, Github, etc.

The implementation was heavily inspired by  , which unsets instead of assigning null, and also clears private properties of safe parents.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance29

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

2

Last Release

763d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/42b585177a4e54729661e41b42130c906babd84936eb7eb595972beb40e3f387?d=identicon)[talkinnl](/maintainers/talkinnl)

---

Top Contributors

[![talkinnl](https://avatars.githubusercontent.com/u/42799774?v=4)](https://github.com/talkinnl "talkinnl (7 commits)")

---

Tags

phpphpunittestingphpunit

### Embed Badge

![Health badge](/badges/talkinnl-dont-leak/health.svg)

```
[![Health](https://phpackages.com/badges/talkinnl-dont-leak/health.svg)](https://phpackages.com/packages/talkinnl-dont-leak)
```

###  Alternatives

[brianium/paratest

Parallel testing for PHP

2.5k118.8M754](/packages/brianium-paratest)[spatie/phpunit-snapshot-assertions

Snapshot testing with PHPUnit

69417.9M511](/packages/spatie-phpunit-snapshot-assertions)[phpunit/phpunit-selenium

Selenium Server integration for PHPUnit

59610.9M150](/packages/phpunit-phpunit-selenium)[yoast/phpunit-polyfills

Set of polyfills for changed PHPUnit functionality to allow for creating PHPUnit cross-version compatible tests

18338.5M841](/packages/yoast-phpunit-polyfills)[ta-tikoma/phpunit-architecture-test

Methods for testing application architecture

10745.9M13](/packages/ta-tikoma-phpunit-architecture-test)[matthiasnoback/symfony-config-test

Library for testing user classes related to the Symfony Config Component

1679.8M395](/packages/matthiasnoback-symfony-config-test)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
