Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7487847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T14:40:19+00:00 2026-05-29T14:40:19+00:00

i have code: class foo { public: bar(const QString& s){} ….. }; int main()

  • 0

i have code:

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;
}

I have memory leak on string “f(QString(“some string text?”));” or not?

Another example

class foo
{
  QUdpSocket socket;
public:
  foo();  
  void send_msq();
};

foo::foo(){
  socket.bind(QHostAddress("192.168.20.1"),50501);
}

void send_msq()
{
  socket.writeDatagram(...);
}

I have any problem on string “socket.bind(QHostAddress(“192.168.20.1″),50501);” ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T14:40:21+00:00Added an answer on May 29, 2026 at 2:40 pm

    There is no memory leak. The QString class manages its own memory (assuming you are talking about this QString.

    You are creating a temporary of that class, which is destroyed when the call to foo::bar returns. At that point, the destructor is run, freeing any memory held by the QString class.

    In general, as long as your resources are managed by classes, and you are not allocating them with new, you don’t need to worry about freeing resources, as the destructor will run when the class instance goes out of scope.

    When you use new, or use resource whose lifetime isn’t managed by a class (like memory returned by malloc or a file returned by fopen (as opposed to fstream, which is a class and cleans up when it is destroyed)), that’s when you need to make sure to clean it up.

    The best way to do that, incidentally, is to wrap such resources in a class that manages the resource’s lifetime through the constructor and destructor, and then use that class instead of the “raw” resource; this is known as the Resource Acquisition Is Initialization pattern.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have the following code: public class Foo { public void Bar() {
I have the following piece of code: class Foo { public Foo() { Bar
Let's say I have the following code: public class Foo { private int x;
Say I have some code like this: class Foo { public: Foo(int v) :
I have a code, class foo : public bar { public: foo(){}; ~foo(){}; };
I have a code, class foo { public: foo(){}; ~foo(){}; }; class bar {
I have the following code: public class Foo {} static class Program { [XmlElement(foo)]
I have the next code: class Foo { public Foo (String param) { ...
Suppose I have a class public class Foo { public Bar Bar { get;
I have this kind of code: public class Foo { public SomeHandler OnBar; public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.