0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

c++ builder / Indy > IndyTextEncoding() > メモリリーク比較 > IndyTextEncoding( 932 ) / IndyTextEncoding( TEncoding::GetEncoding(932) )

Last updated at Posted at 2016-07-29
動作確認
C++ Builder XE4

関連
http://qiita.com/7of9/items/db882fbaa4e610f7c910

m_encSJIS = IndyTextEncoding( TEncoding::GetEncoding(932) );とした時にはTEncoding::GetEncoding()のオブジェクトが開放されないことによるメモリリークが発生する、という情報について。

再現コード

Unit1.h
//---------------------------------------------------------------------------

# ifndef Unit1H
# define Unit1H
//---------------------------------------------------------------------------
# include <System.Classes.hpp>
# include <Vcl.Controls.hpp>
# include <Vcl.StdCtrls.hpp>
# include <Vcl.Forms.hpp>
# include <IdBaseComponent.hpp>
# include <IdComponent.hpp>
# include <IdUDPBase.hpp>
# include <IdUDPClient.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:	// IDE で管理されるコンポーネント
	TIdUDPClient *IdUDPClient1;
private:	// ユーザー宣言
	Idglobal::_di_IIdTextEncoding m_encSJIS;
public:		// ユーザー宣言
	__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
# endif
Unit1.cpp
//---------------------------------------------------------------------------

# include <vcl.h>
# pragma hdrstop

# include "Unit1.h"
//---------------------------------------------------------------------------
# pragma package(smart_init)
# pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{

# if 0 // leak
	m_encSJIS = IndyTextEncoding( 932 );
# else
	m_encSJIS = IndyTextEncoding( TEncoding::GetEncoding(932) );
# endif
}
//---------------------------------------------------------------------------

FastMMを設定して#ifで切り替えた場合の比較をした。

結果

IndyTextEncoding( 932 )の時

qiita.png

IndyTextEncoding( TEncoding::GetEncoding(932) )の時

qiita.png

比較結果

IndyTextEncoding( TEncoding::GetEncoding(932) )の時は「TMBCSEncoding」関連のリークがあり、IndyTextEncoding( 932 )の時はない。

IndyTextEncoding( 932 )を使う方がいいようだ。

他のメモリリークについては要調査。

TIdCriticalSection 関連

TIdCriticalSectionレポートに関しては以下の情報がある。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?