c++ builder / Indy > IndyTextEncoding()の使い方 > 2通り > メモリリークに注意


動作環境
C++ Builder XE4

Indyの関数としてIndyTextEncoding()があり、その使い方の情報が二通りあることに気づいた。

enc := IndyTextEncoding(1252);

IndyTextEncoding(TEncoding.GetEncoding(20127))

上記のリンクで気になる部分は以下の返答。

Remy Lebeau
Posted: Dec 9, 2014 3:17 PM

Just keep in mind that TEncoding.GetEncoding() returns a new TEncoding object that needs to be freed, but the IndyTextEncoding(TEncoding) wrapper does not do that yet (I'm going to add that option soon), so make sure you are not leaking the TEncoding objects that you create.

FastMMでメモリリークを追っているうちに、TEncoding::GetEncoding()関連のリークにたどりついて、上記のリンクにたどり着いた。

TEncoding objectのポインタを一次変数に置いて、終了時にFreeするようにしないといけない。

関連記事

注意が必要な過去の記事

http://qiita.com/7of9/items/51bd31318c6e1332adbf
http://qiita.com/7of9/items/1fa350ce89d5f6cb356b
http://qiita.com/7of9/items/840d1bf4515335b52109