[英]VST host - Leaked objects - Juce/C++
我是構建VST主機時學習C ++的PHP程序員。 我咬的東西可能超過了我的咀嚼能力,但我正在取得一些進步(我認為)!
我在Visual Studio 2010中使用Steinberg VST SDK和JUCE庫。遇到泄漏的對象錯誤,當我搜索收到的錯誤時,我不太了解所找到的解決方案。
這是“輸出”選項卡中的錯誤。 我的程序吐出JUCE Assetion錯誤:
*** Leaked objects detected: 44 instance(s) of class MidiEventHolder
score.exe has triggered a breakpoint
我在juce_amalgamated.h文件中看到此消息:
~LeakCounter()
{
if (numObjects.value > 0)
{
DBG ("*** Leaked objects detected: " << numObjects.value << " instance(s) of class " << getLeakedObjectClassName());
/** If you hit this, then you've leaked one or more objects of the type specified by
the 'OwnerClass' template parameter - the name should have been printed by the line above.
If you're leaking, it's probably because you're using old-fashioned, non-RAII techniques for
your object management. Tut, tut. Always, always use ScopedPointers, OwnedArrays,
ReferenceCountedObjects, etc, and avoid the 'delete' operator at all costs!
*/
jassertfalse;
}
}
這是我編寫的代碼,我相信錯誤是指:
const wchar_t* midiPath = L"C:\\creative\\midi\\m1.mid";
File* fileHard;
FileInputStream* fileInputStream;
fileHard = new File (T("C:\\creative\\midi\\m1.mid"));
fileInputStream = fileHard->createInputStream();
MidiFile * midFile;
midFile = new MidiFile();
midFile->readFrom(*fileInputStream);
midFile->getNumTracks();
midFile->getTrack(0);
也許我正在像使用PHP一樣使用這種語法? 我不太了解RAII技術是什么。
任何幫助我朝正確方向發展的技巧都值得贊賞。
幾件事:
您正在混合寬字符串和Microsoft(“ T
”)字符串。 選擇一個(適合您的API)。
不要說C ++中的new
功能。 幾乎總不是您需要的。 而是使用自動對象:
File fileHard("C:\\creative\\midi\\m1.mid");
FileInputStream * fileInputStream = fileHard.createInputStream();
MidiFile midFile;
midFile.readFrom(*fileInputStream);
midFile.getNumTracks();
midFile.getTrack(0);
那應該擺脫大多數內存泄漏。 您仍然需要按照文檔中所述的方式釋放fileInputStream
。
構建VST插件時不可避免地會發生某些Message對象泄漏,這是Steinberg界面的問題,而不是您的問題。 有關更多信息,請訪問Juce論壇, 網址為http://www.rawmaterialsoftware.com/index.php
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.