Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: Dynamic AudioInputAnalog/AudioAnalyzeFFT1024/AudioConnection instances

  1. #1

    Dynamic AudioInputAnalog/AudioAnalyzeFFT1024/AudioConnection instances

    Is it possible to allocate new AudioInputAnalog/AudioAnalyzeFFT1024/AudioConnection instances then release them again once finished? I have a C++ class that renders a spectrum analyzer to an LED matrix using FastLED, but I only want to use that functionality a small part of the time, and release the memory otherwise.

    If I have something like the following:

    Code:
      // class fields
      AudioInputAnalog *adc1;
      AudioAnalyzeFFT1024 *fft;
      AudioConnection *patchCord1;
    
      // in the class constructor:
      AudioMemory(12);
      adc1 = new AudioInputAnalog(A4);
      fft = new AudioAnalyzeFFT1024();
      patchCord1 = new AudioConnection(*adc1, *fft);
    
      // in the class destructor:
      delete patchCord1;
      delete fft;
      delete adc1;
    I get the following warnings:

    Code:
    src\effect\AudioNoise.cpp:23:10: warning: deleting object of polymorphic class type 'AudioAnalyzeFFT1024' which has non-virtual destructor might cause undefined behaviour [-Wdelete-non-virtual-dtor]
    delete fft;
    ^
    src\effect\AudioNoise.cpp:24:10: warning: deleting object of polymorphic class type 'AudioInputAnalog' which has non-virtual destructor might cause undefined behaviour [-Wdelete-non-virtual-dtor]
    delete adc1;
    ^
    It also makes my program unstable after I have created/destroyed the class a couple of times. Is there a solution, or do I need to keep these objects around for the entire time?

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    27,987
    No, the connection objects must not be destroyed. Other objects hold pointers to them, and currently there's no way to make the rest of the system "forget" a connection.

  3. #3
    Thanks for the very quick reply and for confirming my suspicions. Sounds like it's time for me to do a bit of refactoring of my code to take that into account...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •