eGospodarka.pl
eGospodarka.pl poleca

eGospodarka.plGrupypl.comp.programmingAutomatic Reference Counting › Re: Automatic Reference Counting
  • Path: news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!.P
    OSTED!not-for-mail
    From: Borneq <b...@a...hidden.pl>
    Newsgroups: pl.comp.programming
    Subject: Re: Automatic Reference Counting
    Date: Mon, 14 Aug 2017 15:10:41 +0200
    Organization: ATMAN - ATM S.A.
    Lines: 53
    Message-ID: <oms7gf$bbk$1@node2.news.atman.pl>
    References: <omqmm6$vvs$1@node2.news.atman.pl>
    <7...@g...com>
    <omqrh3$4kl$1@node2.news.atman.pl>
    <e...@g...com>
    <omrm61$r61$1@node2.news.atman.pl>
    <b...@g...com>
    NNTP-Posting-Host: 91.239.205.105
    Mime-Version: 1.0
    Content-Type: text/plain; charset=utf-8; format=flowed
    Content-Transfer-Encoding: 8bit
    X-Trace: node2.news.atman.pl 1502716239 11636 91.239.205.105 (14 Aug 2017 13:10:39
    GMT)
    X-Complaints-To: u...@a...pl
    NNTP-Posting-Date: Mon, 14 Aug 2017 13:10:39 +0000 (UTC)
    User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101
    Thunderbird/52.2.1
    In-Reply-To: <b...@g...com>
    Content-Language: pl
    Xref: news-archive.icm.edu.pl pl.comp.programming:211044
    [ ukryj nagłówki ]

    W dniu 14.08.2017 o 10:31, M.M. pisze:
    > Widzę że coś jak QMutexLocekr w Qt, tylko że mutex locker samo
    > odblokowuje mutex a nie zwalnia pamięć :)
    > http://doc.qt.io/qt-4.8/qmutexlocker.html

    W poniższym przykładzie listy cyklicznej jest coś źle.
    Shared nie powinien zwalniać, a zwalnia wszystkie z wyjątkiem jednego i
    to przed opuszczeniem test(),
    zamiana na weak skutkuje tym że jest na zmianę tworzenie i zaraz
    zwalnianie. Coś nie tak, jak w teorii.

    #include <memory>
    #include <iostream>
    using namespace std;

    class Node
    {
    private:
    int n;
    public:
    Node(int n): n(n)
    {
    cout << "Constructor Node is called " << n <<endl;
    }
    ~Node()
    {
    cout << "Destructor Node is called " << n << endl;
    }
    shared_ptr<Node> prev;
    };



    int test()
    {
    shared_ptr<Node> node = shared_ptr<Node>(new Node(0));
    shared_ptr<Node> first = node;
    for (int i = 1; i < 5; i++)
    {
    shared_ptr<Node> prev = node;
    node = shared_ptr<Node>(new Node(i));
    node->prev = prev;
    }
    node->prev = node;
    printf("====\n");
    return 0;
    }

    int main()
    {
    test();
    return 0;
    }

Podziel się

Poleć ten post znajomemu poleć

Wydrukuj ten post drukuj


Następne wpisy z tego wątku

Najnowsze wątki z tej grupy


Najnowsze wątki

Szukaj w grupach

Eksperci egospodarka.pl

1 1 1

Wpisz nazwę miasta, dla którego chcesz znaleźć jednostkę ZUS.

Wzory dokumentów

Bezpłatne wzory dokumentów i formularzy.
Wyszukaj i pobierz za darmo: