Skip to content
  • 0 Votes
    2 Posts
    219 Views
    Christian EhrlicherC

    There is no leak. How do you measure? Please provide a minimal, compileable example of the problem.

  • 0 Votes
    4 Posts
    368 Views
    D

    @Christian-Ehrlicher said in Strange memory allocation issues?:

    @Dariusz said in Strange memory allocation issues?:

    Any idea why converting QString to stdString causes memory allocation issues?

    I don't know what you're trying to achieve - if you want to look for memory leaks use the appropriate tools but those two functions don't leak any memory.

    /edit:
    and btw: there is more than one new operator: https://en.cppreference.com/w/cpp/memory/new/operator_new

    Meh no luck, added other ones but failed to track it :/

    // 1. Simple allocation void *operator new(std::size_t size) { if (mRecordData) { allocations++; total++; void *p = std::malloc(size); if (!p) { badAllocs++; totalBadAllocs += size; throw std::bad_alloc(); } totalSizeAllocated += size; return p; } return std::malloc(size); } // 2. Array allocation void *operator new[](std::size_t size) { return ::operator new(size); } // 3. No-exception allocation void *operator new(std::size_t size, const std::nothrow_t &) noexcept { if (mRecordData) { allocations++; total++; void *p = std::malloc(size); if (!p) { badAllocs++; totalBadAllocs += size; } return p; } return std::malloc(size); } // 4. Array no-exception allocation void *operator new[](std::size_t size, const std::nothrow_t &nt) noexcept { return ::operator new(size, nt); } #if __cplusplus >= 201703L // 5. Aligned allocation (C++17 onward) void *operator new(std::size_t size, std::align_val_t al) { if (mRecordData) { allocations++; total++; void *p = _aligned_malloc(static_cast<size_t>(al), size); if (!p) { badAllocs++; totalBadAllocs += size; throw std::bad_alloc(); } totalSizeAllocated += size; return p; } return _aligned_malloc(static_cast<size_t>(al), size); } // 6. Aligned array allocation (C++17 onward) void *operator new[](std::size_t size, std::align_val_t al) { return ::operator new(size, al); } #endif // Corresponding delete overloads void operator delete(void *p) noexcept { if (mRecordData) { deallocations++; total--; } std::free(p); } void operator delete[](void *p) noexcept { ::operator delete(p); } void operator delete(void *p, const std::nothrow_t &) noexcept { ::operator delete(p); } void operator delete[](void *p, const std::nothrow_t &) noexcept { ::operator delete(p); } #if __cplusplus >= 201703L void operator delete(void *p, std::align_val_t) noexcept { ::operator delete(p); } void operator delete[](void *p, std::align_val_t) noexcept { ::operator delete(p); } #endif

    Bummer!

    Just wanted a lightweight way of tracking my test allocations/memory footpring :c
    I know there is valgrind/other ones, but they are harder to set up for per-function tests/etc inside gtest as far as I can tell :/

  • 0 Votes
    1 Posts
    263 Views
    No one has replied
  • 0 Votes
    10 Posts
    1k Views
    KH-219DesignK

    Just a note about a non-Valgrind, windows-specific leak-checking method:

    https://docs.microsoft.com/en-us/visualstudio/debugger/finding-memory-leaks-using-the-crt-library?view=vs-2019

    It has been a while since I have done any extensive work on a Microsoft platform, but in my recollection crtdbg.h can do many helpful diagnostic things, although it is sometimes tricky to get all the debug build settings configured in the way that will trigger the features you seek.

  • 0 Votes
    5 Posts
    824 Views
    nageshN

    @Roysten-Rigobert Why don't you create menu/actions at once by making menu as member variable?

    and in contextMenu(QPoint) slot call only the menu->exec(mapToGlobal(pos));

  • 0 Votes
    2 Posts
    340 Views
    SGaistS

    Hi,

    This will depend on your widgets and what their content. It will also depend on the device that runs your application. But more seriously, unless you are under very high memory constraints you should allocate the widgets commonly used from the start and the ones that are less often used when they are needed.

  • 0 Votes
    13 Posts
    1k Views
    S

    As @Christian-Ehrlicher already said: the image gets deleted when the thread object is deleted. Do you delete the thread object?

    Furthermore, I am not sure how you are trying to check if the memory is actually freed. The operating system might not be able to show you this. Your software will request memory from the OS when necessary, but can choose to keep it for later allocations when memory is freed. The only way you can test this is by repeatedly allocating and deallocating an image. If the memory usage does not grow then memory is correctly freed even if the OS does not show you this.

  • zooming an SVG image

    Unsolved QML and Qt Quick
    1
    0 Votes
    1 Posts
    644 Views
    No one has replied
  • Class properties in stack or heap?

    Solved C++ Gurus
    15
    0 Votes
    15 Posts
    4k Views
    Chris KawaC

    @Exotic_Devel In the link I posted is a full list of implicitly shared classes: list of classes. What I said applies to all of them and yes, QMap is one of them.

  • 0 Votes
    18 Posts
    7k Views
    jsulmJ

    @VikramSamy said in QT5 application crashed after running for some long time.....:

    so my question which is the better, use as my original code and delete the Qstringlist somewhere, or create the QStringlist in the stack and let it get destroyed by itself after getting out of scope as above ??

    There is no generic answer to this question as it simply depends on the use case. If you only need this list in that method then you simply allocate it as local variable. Having it as member variable in the class is only needed if you need the list at several places in your class.
    By the way this is not heap allocation:

    private: QStringList TableMessages; QStringList TableMessagesNOT;
  • 0 Votes
    10 Posts
    2k Views
    S

    Okay I found the culprit in an unexpected corner.

    I decided to completely strip it to the absolute bare minimum:

    int main(int argc, char *argv[]) { QCoreApplication app (argc, argv); // initialization Sms_notifier notifier(true, 5); notifier.notify( "+0123456789", "Lorem Ipsum is simply dummy text of the printing and typesetting industry. "); qWarning() << "done, looping"; while(true) { QCoreApplication::exec(); } } Sms_notifier::Sms_notifier(bool test, int interval_length_milliseconds) : QObject (NULL) ,m_test (test) ,m_interval_length_milliseconds(interval_length_milliseconds) ,m_manager () ,m_timer () ,m_addressee() ,m_payload() { m_timer.setSingleShot(true); QObject::connect(&m_manager, &QNetworkAccessManager::finished, this, &Sms_notifier::on_nam_finished); QObject::connect(&m_timer, &QTimer::timeout, this, &Sms_notifier::on_timer_elapsed); } Sms_notifier::~Sms_notifier() { } bool Sms_notifier::notify( const std::string addressee, const std::string payload ) { m_addressee = addressee; m_payload = payload; return notify(); } bool Sms_notifier::notify() { QNetworkRequest request; QByteArray data; m_manager.post(request, data); return false; } void Sms_notifier::on_nam_finished(QNetworkReply* reply) { QNetworkReply::NetworkError error = reply->error(); reply->deleteLater(); if (error != QNetworkReply::NetworkError::NoError) { m_timer.start(m_interval_length_milliseconds); } else { qWarning() << "success"; m_addressee.clear(); m_payload.clear(); } } void Sms_notifier::on_timer_elapsed() { notify(); }

    It turns out it was still leaking while there was no network. So I stripped away all libraries that were linked, and it still leaked.

    Eventually my eye struck this in the .pro file:

    QMAKE_CXXFLAGS += -fsanitize=address QMAKE_CFLAGS += -fsanitize=address QMAKE_LFLAGS += -fsanitize=address -lasan

    This was added to detect memory leaks and report them when the application quits. After removing this, the excessive "memory leak" was gone.

    I am assuming that the address sanitizer allocates memory for each allocation done by the application, for its own administration purposes. I suspect that when the application releases the allocated memory, the sanitizer holds on to the respective administration data until the application quits. This could explain why when I remove the sanitizer it also removes the leak.

    Well, thanks everyone for your input!

  • 0 Votes
    11 Posts
    3k Views
    K

    @aowoo said in How to access IO port in QT?:

    directly read and write to the I/O port

    AFAIK, It's impossible for Windows && Linux:

    On Windows you need in a special driver (It is not enough to use just some DLL's, because you need in a driver. Most likelly, that inpout32.dll has a pre-compiled driver in own resources and loads this driver in runtime).

    On Linux you need in a special permissions too.

  • 0 Votes
    11 Posts
    4k Views
    JKSHJ

    Hi @robcreamer, this is outside my expertise, but I suggest you subscribe to the Interest mailing list (http://lists.qt-project.org/mailman/listinfo/interest ) and post your sample code + 122.7-hour log there. I'm sure one of the Qt engineers on the list can tell you what's happening.

  • 0 Votes
    2 Posts
    872 Views
    F

    I am such an idiot... maxSize is in bytes and I have divided it by 16... now it works.

  • 0 Votes
    1 Posts
    642 Views
    No one has replied
  • 0 Votes
    6 Posts
    2k Views
    mrjjM

    @Stefan-Monov76
    The automatic deletion of QObject childs by the parents is used in whole Qt frame work and
    is fully documented and will not change in any version.
    http://doc.qt.io/qt-5/objecttrees.html

  • 0 Votes
    2 Posts
    896 Views
    raven-worxR

    @Mathan-M
    Following Java code can be used (Can be easily used from JNI if needed)

    // android.os.StatFs StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath()); long bytesAvailable = (long)stat.getBlockSize() *(long)stat.getBlockCount();
  • 0 Votes
    1 Posts
    704 Views
    No one has replied