0
我有代碼:C++內存泄漏或不
class foo
{
public:
bar(const QString& s){}
.....
};
int main()
{
.....
foo f;
for(int i = 0; i < 100; i++)
f.bar(QString("%1").arg(i));
....
return 0;
}
我有字符串內存泄漏 「F(QString的(」 一些文本串 「));」或不?
又如
class foo
{
QUdpSocket socket;
public:
foo();
void send_msq();
};
foo::foo(){
socket.bind(QHostAddress("192.168.20.1"),50501);
}
void send_msq()
{
socket.writeDatagram(...);
}
我有 「(QHostAddress(socket.bind」 192.168.20.1上串中的任何問題 「),50501);」 ?
你的代碼不能編譯。我會先做。 – Sven 2012-02-09 05:44:45
可能不是。 'QString'是爲了追蹤自己的記憶,而你只是傳遞一份副本。我假設'foo'有'xxx operator()(QString const&)'成員。 – 2012-02-09 05:45:19
你的意思是f.bar(QString(「some string text?」)); ? – grieve 2012-02-09 05:46:19