Giter Site home page Giter Site logo

Memory Leak Detect? about unity HOT 3 CLOSED

throwtheswitch avatar throwtheswitch commented on July 24, 2024
Memory Leak Detect?

from unity.

Comments (3)

mvandervoord avatar mvandervoord commented on July 24, 2024

Hi Mark

Unity currently supports memory leak detection by abstracting malloc, etc. You can find this in the extras directory.

As I sidenote: It's not a feature we spend a lot of time promoting because memory leak detection is rarely a good fit with unit testing. It's a common paradigm for a particular unit to produce memory while another unit consumes it. Testing of real-world memory handling can be handled much more effectively with mocking if you're insisting on doing it in Unit Testing... but I'd really recommend doing it in higher level tests as well (system testing, etc). You are going to want to know if your entire application leaks memory and checking individual unit tests isn't as likely to catch such a thing.

I find that memory leak detection is one of the features that a lot of Unit Tests list (including this one) because it's easy to implement, but it's really not used often because it's the wrong fit.

Just an observation. ;)

Mark

from unity.

markfink avatar markfink commented on July 24, 2024

Thanks for the insights. Just to make sure I got it all... Are you saying one should not use unity for higher level tests? Which tools are you recommending?

Is that all I have to do to activate the feature, or do I need additional asserts etc.?

#include "unity_fixture_malloc_overrides.h"

from unity.

mvandervoord avatar mvandervoord commented on July 24, 2024

You need to use all of the unity_fixtures extras. The actual implementation of the memory overrides is in the unity_fixture.c module, which unfortunately means you have to take it all. If I remember correctly, there is also a bit of a challenge making sure that unity_fixture_malloc_overrides.h gets included even from the src module to override the malloc calls.

The memory tools should be split out from the fixture extension, since they aren't REALLY dependent on each other... just stuck in the same C module at this point.

Anyway, I use Unity for all the unit and interaction testing I do. For system testing I usually end up spinning my own framework using Ruby and Arduino for hardware interaction. The memory leak detection stuff, when dynamic memory is required, is a tricky one to fit in. I usually try to bake it into my release code itself, then check it during system tests. This might be more overhead than your application can support, which would suggest that you might want to do one of two things:

  • break system testing into two levels... one that runs code WITH extras like memory leak detection turned on, and another which is your actual release code
  • create high-level integration tests where you are combining multiple C modules together in order to properly support memory tests (you'd need all the modules that create or consume the memory). This is back to being a good fit for Unit Testing (and therefore Unity). The challenge of integration tests (no matter what framework) is that they can start to pull in a lot of mock/stub interfaces. It's doable, but might be more challenging than you hope.

Mark

from unity.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.